It would be better if u post the entire code without just propagating the updates like an AJAX enabled page :)
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
Since word is defined as 5 characters, and you enter "hello", the \0 at the end overwrites memory outside your string. Try increasing the size of word for starters.
WaltP
Posting Sage w/ dash of thyme
10,505 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
Read the post from S.O.S.
WaltP
Posting Sage w/ dash of thyme
10,505 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
won't u forgive me for 1st mistake in my 1st post!!
If u don't have any technical sugestion about the problem over which I have shown some effort at least then plz don't send them.
This may discourage others!
Buddy we not discouraging anyone, we just need the code i mean the complete code which you have written to understand the problem at hand and help you out. And by the way we no discouraging anyone, just asking a little dedication from your side so you can one day program with the basics on your fingertips.
Hope it helped, bye.
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
First, this indicates that you seem to be compiling as C++ (or C99) instead of C(89).
int main()
{
char word[10];
char *a,*p,*b;
b=p=word;
//b is storing the base address for future reference
int flag=0,len,count=0,disp=0;
char buf[BUFSIZ];
char *c;
a=buf;
Staying in C or staying in C++ is preferable to mixing while you're starting out.
You use fgets from the start.
if ( fgets(buf, sizeof(buf), stdin) != NULL )
And then you drop the ball and mix it with scanf .
scanf("%s",&word);
And improperly. User Input: Strings and Numbers [C]
Now scanf is an unruly beast, so if you are well versed in what it is you are telling it, just avoid it.
I think you've got the print and the fix-it backwards here.
printf ("Thank you, you entered >%s<\n", buf);
/*
* Now test for, and remove that newline character
*/
if ( (c= strchr(buf, '\n')) != NULL )
*c = '\0';
I haven't looked much more at the code, but it's starting to sound like strstr . Strings: Finding a Substring
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314