Need hep with my semantic error


 
Thread Tools Search this Thread
Top Forums Programming Need hep with my semantic error
# 1  
Old 12-10-2012
Need hep with my semantic error

Code:
while(EOF != (c = fgetc(filePtr))) 
 {

    if ((c == ' ') || (c == '\n') || (c == '\0'))
    {
        if (c == '\0')
        {
            continue;
        }
	
	printf("%s",cc);
	printf("%c\n");
	memset(cc, 0, sizeof cc);

    }
	else
	{ 
	cc[i]=c;
	i++;
	}

I supposed from that code to print word by word from text file but there is something wrong with <<<<memset(cc, 0, sizeof cc);>>>>>
it give me like that
Image
# 2  
Old 12-10-2012
Post your entire code. From the look of those warnings, there may be a problem with the way you declared your variables.

You also don't ever null-terminate your array, putting a '\0' as the last character, so printf and anything else that uses strings won't know where it ends.
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 12-10-2012
ok thank you all in advance I forgot to put i=0;
to start from the first location of char array but any way can anyone help me with that little freaky symble at the end of the word
Code:
while(EOF != (c = fgetc(filePtr))) 
 {

    if ((c == ' ') || (c == '\n') || (c == '\0'))
    {
        if (c == '\0')
        {
            continue;
        }
	
	printf("%s",cc);
	printf("%c\n");
        i=0;
	memset(cc, 0, sizeof cc);

    }
	else
	{ 
	cc[i]=c;
	i++;
	}

Image
# 4  
Old 12-10-2012
Post your entire code.

What is this for?
Code:
printf("%c\n");

%c means 'print one character that I passesd as an argument' but you passed no argument. It's going to print whatever garbage happens to be on the stack as %c.
This User Gave Thanks to Corona688 For This Post:
# 5  
Old 12-10-2012
ok thank you Eng. Corona688
the mistake was
Code:
while(EOF != (c = fgetc(filePtr))) 
 {

    if ((c == ' ') || (c == '\n') || (c == '\0'))
    {
        if (c == '\0')
        {
            continue;
        }
	
	printf(cc); // don't assign it as string
	printf("%c\n");
	i=0;
	memset(cc, 0, sizeof cc);

    }
	else
	{ 
	cc[i]=c;
	i++;
	} 
	 
	

  }

# 6  
Old 12-10-2012
No, the wrong code is still there:

Code:
printf("%c\n"); // What will %c become?  Impossible to say!  Stack value roulette.

Also, your printf(cc); is wrong, because it will misbehave if cc happens to have % characters in it, which printf will take to be format specifiers.

Really, all you need is
Code:
printf("%s\n", cc);

which will do everything in 1 printf and behave.
Login or Register to Ask a Question

Previous Thread | Next Thread

3 More Discussions You Might Find Interesting

1. Programming

Tool for checking syntactic and semantic mistakes

Hello, it is easy to make mistake in c code. What ide or tool are you using for checking syntactic and semantic mistakes? Jarda (1 Reply)
Discussion started by: berk
1 Replies

2. UNIX for Dummies Questions & Answers

Hep with script to monitor directory

Hello, I am a newbie who is attempting to write a script to monitor a directory for a set of 3 files that I am expecting to get ftp'd. Occasionally, we suspend operations for maintenance etc. but we still get the files so there can be more than 1 set. If there is more than 1 set, I would like... (2 Replies)
Discussion started by: cmf00186
2 Replies

3. UNIX for Dummies Questions & Answers

syntax and semantic check

Does the shell perform a syntax and semantic check before commands are sent to the kernel? Ravioli (3 Replies)
Discussion started by: ravioli
3 Replies
Login or Register to Ask a Question