![]() |
|
#1
|
|||
|
|||
Loop problemsMost of the header files that I know how to use did not come with my compiler, so recently I have been programming some functions that do some of the same things. I need the practice anyway. This program was suppost to test a string length function, and function that finds substrings. But my loops are having lots of errors. I am using Borland 5.5 on Win XP, and if anyone can help it would be greatly appreciated. I'm going to post all the code so that you might be able to find the problem better.
CPP / C++ / C Code:
Last edited by ambeco : 01-Mar-2004 at 12:31.
Reason: error with another function and had idea
|
|
#2
|
||||
|
||||
|
Quote:
Quote:
Two things I notice: On the line defining placeofsub you are missing something that will cause many errors, On the function definition above what are the parameter types? |
|
#3
|
||||
|
||||
|
Hi Ambeco.
This may not be the source of your problem but would definitely help for readability. In addition remember that you can overload functions, so instead of your function headers reading: CPP / C++ / C Code:
Change them to give the variable types as well: CPP / C++ / C Code:
I am not 100% certain, but I believe that C++ will read this as an overload function with integers instead of char*'s |
|
#4
|
|||
|
|||
|
Well, my free version of Borland++ has all of the headers that I have
tried to use so far; where did you get yours? I ran BCC on your program and got 15 compile errors. Here are the first few: Quote:
Now look at what the compiler is telling you: your line 30 is: CPP / C++ / C Code:
Since you didn't declare types of the arguments, the default behavior of C (and, by extension of C++) is to treat them as ints. This leads to lots of errors inside the subroutine. change this to something like CPP / C++ / C Code:
or CPP / C++ / C Code:
Now the compiler knows that they are pointers to char. Before you recompile with this change, note error #2379: missing semicolon. Fix it (by adding a semicolon, naturally). Now, use compiler messages to get a clean compile. That won't guarantee that your program is correct, but at least you will have something to look at to see if it's OK OK? Dave |
|
#5
|
|||
|
|||
Thanks Guys!I added the char* to the declarations and added the ; and messed with a few other things, so now it compiles. I will have to add bits of code to prevent errors but... thats a different story. In the future I will remember to include the errors. Sorry about the confusion!
|
|
#6
|
|||
|
|||
HmmmmCPP / C++ / C Code:
|
|
#7
|
||||
|
||||
|
Your for statements are never being processed. You are telling your loop statement to process only when loc1 is equal to your string length which is never, because your loc1 doesn't get indexed. Use:
CPP / C++ / C Code:
in both of your for statements. |
|
#8
|
|||
|
|||
|
When I have programs with several new routines and the big program
doesn't give expected result, sometimes I test the individual routines in separate programs. For example: I think that your len() function gives the wrong answer. (It returns a result that is 1 more than the actual string length). Try the following: CPP / C++ / C Code:
The first string has length = 24 The second has length = 6 The third has length = 0 (Note that your test cases should always include boundary conditions --- i.e. make sure it's OK for all strings, including an empty string.) Now if you have full confidence in this function, you can concentrate on any remaining problems. Regards, Dave |
|
#9
|
|||
|
|||
|
Quote:
|
Recent GIDBlog
Writing a book by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| burning problems PLEASE PLEASE HELP | kelticeire | Computer Hardware Forum | 4 | 01-Dec-2006 16:39 |
| Chaintech Geforce 5600 FX problems | bartster74 | Computer Hardware Forum | 8 | 04-May-2004 14:16 |
| C switch / loop issue | spudtheimpaler | C Programming Language | 4 | 20-Feb-2004 21:45 |
| CD Burner Problems | Joe9995 | Computer Hardware Forum | 0 | 07-Feb-2004 11:47 |
| Installation problems | arman | Apache Web Server Forum | 3 | 03-Feb-2004 13:02 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The