![]() |
|
#1
|
|||
|
|||
Using String function in C language..this program is about FLAMES.. the so called "game"..and i think many of you are familiar about this one..am i right?.. this code only prints the total letter of the two names entered and its corresponding letter after summing it up..instead of the the canceled letters(the same letters that the two names have/ common letters..as what the FLAMES rule is..canceling and summing the canceled letters..) my code problem is, i don't know how to count the canceled letters, yet i know how to sum it up and its corresponding letter in FLAMES. for example.. 1st name: Marie Yu 2nd name: Mark Cruz.. 2 m's will be canceled, 2 a's, 3 r's, and 2 u's..sO, the total letters that were canceled were 9..so, 9 is "A" which means "ADMIRED"..1-FRIENDS, 2-LOVE, so on... my code is: im using C LANG. compiler: BORLAND C++., CPP / C++ / C Code:
thanks ahead.!=) |
|||
|
#2
|
||||
|
||||
Re: using String function in C languagewelll..
I would suggest dividing the problem into functions. One of the functions would divide a given strings into characters and assign weights to each such unique character which would indicate the number of times it has occured in a given string. This could be done by creating an array of structs dynamically (see example below). A second function would then take (pointers to)two such newly created arrays and in that function I would: 1. determine which of the two strings is shorter in size. 2. then take the shorter string as the base string and then do a character by character comparison of each of the letters of the shorter string with each letter of the larger string. 3. When a match is found then I would add the weights of the characters which have been found to match. Your implementation may vary. I may convert the arrays into arrays of structs with the struct having two members, one being the character and the other being the weight of the character. Comparison would be a bit more difficult. You may have to compare the character part of the structure until you reach the 'null' character in the shorter array of structs. Hence 'Marie Moon' would transform into {(2,m),(1,a),(1,r),(1,i),(1,e),(2,o),(1,n),'\0'} and Mark Cruz would become {(1,m),(1,a),(2,r),(1,k),(1,c),(1,u),(1,z),'\0'} In the case above both the structs are equal in length. You may come across long strings with a high rate of repetition of chars being compared with relatively shorter strings with very little or no repetition. In cases like that the transformation would leave the former string shorter than the latter in the array of structs. Anyways, I guess I have given you something to work with...I hope it helps..and you can use isxxx types of functions from ctype.h to ignore white space incase the string contains two or more words. __________________
Hope to hear from you guys! -------------------------------------------------- Best Regards, Aijaz Baig. |
|
#3
|
||||
|
||||
Re: using String function in C languageHi there,
sorry I guess I didn't read your question thoroughly. I think you wanted to know how to count the cancelled letters. Well..what I might do is I might first concatenate both the strings and then remove all the white space that occurs. Then I would apply any sorting algorithm on that string which would then sort the characters (from a to z). Hence we would be left with a sorted strings which may have substrings composed of the same character. I would have to just scan the string of chars checking for repetition of chars and have a counter that would increment whenever I come across a repetition. Note that since we are only concerned with the total number of letters that cancel or the total 'number of repetitions' we do not need to remember the characters which cancel. One dummy char variable should do the job. __________________
Hope to hear from you guys! -------------------------------------------------- Best Regards, Aijaz Baig. |
|
#4
|
|||
|
|||
Re: Using String function in C languageThanks guys! I understand what you were telling but can you please give me a code that can help me further? In accordance to what I posted? About FLAMES!
|
|
#5
|
|||
|
|||
Re: Using String function in C languageIs this what you're looking for?
CPP / C++ / C Code:
|
|
#6
|
|||
|
|||
Re: Using String function in C languageactually, i dont know where should i put what you have added..where should i put that one??
|
|
#7
|
|||
|
|||
Re: Using String function in C languageTry putting it here:
Quote:
|
|
#8
|
||||
|
||||
Re: Using String function in C languagehmmm..pretty compact code fakepoo!!!..never occured to me it could be this easy...well...you thought in terms of the problem at hand and I wandered in terms of representation...making ur suggestion a much more natural solution. Do you know where I could learn some methodologies of creating algorithms like this. Like programming methodologies for instance.
Hope to hear from you __________________
Hope to hear from you guys! -------------------------------------------------- Best Regards, Aijaz Baig. |
|
#9
|
|||
|
|||
Re: Using String function in C languageWell, I don't exactly know where a good site is for creating algorithms with methodologies but maybe some of the others in this forum would know.
Basically, if there is a section of code that performs a specific task, I like to put it into it's own function to make the code cleaner. This makes it easier to debug, reuse, and read to get an understanding of what is happening. In order to create a function, you need to figure out exactly what the function needs to do, what it needs to return as output, and what it needs as input in order to perform it's task. Also, commenting in your code is a good habit to get into so that you can look back at the code at a later time and realize what is happening without having to dissect it again. For the most part, continue practicing and you'll get better as you go. A forum like this one is very helpful for getting advice about your code and ways you can improve it. |
|
#10
|
|||
|
|||
Re: Using String function in C languageCPP / C++ / C Code:
fakepoo, don't forget to use proper const correctness! :davis: |
Recent GIDBlog
GID Spam Detector 1.1.0 by gidnetwork
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Flex and bison coding | lucky88star | C++ Forum | 5 | 24-Dec-2007 11:57 |
| Need Help with input files. | Efferus | C++ Forum | 2 | 24-Nov-2007 16:19 |
| [Include] Doubly-linked List | dsmith | C Programming Language | 6 | 14-Apr-2006 13:12 |
| Help wit my source code compiler errors | Krandygrl00 | C++ Forum | 1 | 06-Jun-2005 08:14 |
| Revising Script style ?????? | pepee | MySQL / PHP Forum | 4 | 14-Apr-2004 04:59 |
Network Sites: GIDNetwork · GIDApp · GIDSearch · Learning Journal by J de Silva, The