![]() |
|
#1
|
|||
|
|||
How to finish this C Code?Objective: Input: "This is funny" "end (signals as stop)" Output "The longest string is: funny"
CPP / C++ / C Code:
Last edited by LuciWiz : 16-Jul-2009 at 04:52.
Reason: Please insert your C++ code between [cpp] & [/cpp] tags
|
|||
|
#2
|
|||
|
|||
Re: How to finish this C Code?What are "StringLength()" , "GetLine()" , "simpio.h" and "genlib.h" ?
If you want folks to help you should stick with standard C functions and header files. acm.uiuc.edu/webmonkeys/book/c_guide/ If you created "simpio.h" and "genlib.h" then you should include them with your code. Do not use "system("pause"); " . It is not standard C. It is a traitor and part of the Empire. Instead use getchar(); to pause. "string.h" ( the header file you get strcmp() from ) also has a function "strlen()" to use instead of "StringLength()" . It has many other handy string related functions as well. (see string.h in the above reference) If you want to find the longest string and have it on hand you will need to be able to store it for a while. You will need at least two string arrays. One to store the longest and one to store the current input strings. I would suggest learning to use getchar() to get your input into arrays. Here are some ideas: CPP / C++ / C Code:
Last edited by Howard_L : 16-Jul-2009 at 10:08.
|
|
#3
|
||||
|
||||
Re: How to finish this C Code?Quote:
Yes...whatever that stuff in the [c]...[/c] tags was rather ugly. CPP / C++ / C Code:
Output: Code:
MxB |
|
#4
|
|||
|
|||
Re: How to finish this C Code?Well Mx, that is nice looking.
I was trying to cram some basic C string mechanics in there since I think it's important and the OP seemed new. But they've probably gone on to Javaland now anyhow so what the hey... At least I got some practice in and was reminded of strtok(). Thanks! |
|
#5
|
|||
|
|||
Re: How to finish this C Code?Sorry to trouble both of you and sorry for being a little late given my drenched internet, but I somehow got my logic all messed up.
I have a good logic, but it never seems to match up with anything C or math. OK I haven't learnt char yet, so I am not expected to use it and I'll wipe the system("pause") out, thanks for the tip. What is confusing me is this last bit here CPP / C++ / C Code:
I don't know how to fix it without making it a very complicated code which has a 50% chance of working. Maybe I need to go do some meditation to clear my mind up Thanks! |
|
#6
|
|||
|
|||
Re: How to finish this C Code?Code:
Is this what you are learning in a class? great...... The class should be teaching you to use standard header files and the functions they provide. You got no time to be dilly dallyin around with makin up sissy words.... Is this supposed to be C or C++? There is no standard "string" datatype in C as you have in your first post above. The files: #include "simpio.h" #include "genlib.h" #include <strlib.h> (did you mean stdlb.h ?) ...are not standard C header files so we don't know anything about the functions they provide. Same for these functions: GetLine() StringLength() So , we can't help you if you insist on using this stuff. If you have defined those functions in those files then you should supply us with them too. You program could easily be written using the functions found in the standard libraries: #include <stdio.h> #include <string.h> In those header files you can find the functions to replace the ones you are trying to use. strcmp = strEqual() fgets() = sGetLine() strlen() = StringLength() Would you like to try that? THEN we could help... |
|
#7
|
|||
|
|||
Re: How to finish this C Code?Wow *bummed* OK I'll do just that.
|
|
#8
|
|||
|
|||
Re: How to finish this C Code?Bummer - NOT , just make the substitutions and move on , your a perfectionist aren't you????.
You will need to use standard C datatypes as well. Instead of String you will need to declare a C string ( an array of type char ): Here is a basic outline of one way of doing this for you to think about: CPP / C++ / C Code:
fgets() is a little tough so here is an example of fgets() usage to keep you interested: CPP / C++ / C Code:
Code:
|
|
#9
|
||||
|
||||
Re: How to finish this C Code?Quote:
Apparently YOU don't know ANYTHING about abstract art, eh?! MxB |
Recent GIDBlog
Once again, no time for hobbies by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Trouble integrating console code into GUI | Barman007 | Java Forum | 18 | 15-May-2008 14:05 |
| How to sort random access file? | wmmccoy0910 | C Programming Language | 12 | 04-Sep-2006 04:40 |
| Here it is again! 35% - 40% off For Life! | my-e-space | Web Hosting Advertisements & Offers | 0 | 20-Apr-2006 15:48 |
| Guidelines for posting requests for help - UPDATED! | WaltP | C Programming Language | 0 | 21-Apr-2005 03:44 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The