Hi,
Here is my code I tried to count occurence of string "01.01."in FILE .
There is no output coming,it shows blank window. Please guide me regarding this.
Munisamy
Hi,
Here is my code I tried to count occurence of string "01.01."in FILE .
There is no output coming,it shows blank window. Please guide me regarding this.
Munisamy
1) void main() is incorrect. it should be int main(void)
2) what you are doing is
str1 and str2 are the starting addresses of the array elements and cannot be equalCode:if(str1==str2) count++;
use strcmp() for comparing the strings
3)strcpy() is used incorrectly in your code. strcpy is defined as
it will copy the string src to tempCode:char *strcpy(char*temp,const char *src)
4) what are you trying to do with fseek() ?? you are positioning the pointer to the end of file rite at the start..that wont do.
5) clrscr() is nonportable..check the faq for ways to clear the screen
6) getch() is defined in conio.h so include that header.
7) strcpy() and strcmp() are defined in string.h so include that as well.
8) dont forget to change void main() to int main (void)
edit: as quzah pointed out, i missed the "=" sign in the if() statement..
Last edited by PING; 02-26-2005 at 02:26 AM.
Code:>+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.[-]>++++++++[<++++>-] <.>+++++++++++[<++++++++>-]<-.--------.+++.------.--------.[-]>++++++++[<++++>- ]<+.[-]++++++++++.
Just to add..
> strcpy(str2,fp);
Use fgets to read a line from a file. Simply referring to fp here doesn't cause the file to be read.
Also, even for such a small program, your indentation is poor.
> char str2[6];
You could never store a valid string in that array which would ever match char str1[]="01.01.";
because it's at least one character too short.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
You've missed the error here where they're using the assignment operator instead of the comparison operator. If they were in fact trying to compare the two addresses (which is allowable) then they should be using == and not =Originally Posted by PING
That's actually the only "error" in that code. And if in fact those are the names of arrays, their compiler would be telling them this. I'd suggest the origional poster pay attention to their compiler's warnings and errors. If they aren't getting any, then I'd suggest turning them on.
Quzah.
Hope is the first step on the road to disappointment.