g.c:12: warning: passing argument 1 of 'fgets' from incompatible pointer type
g.c:12: error: too few arguments to function 'fgets'
g.c:14: error: 'sc' undeclared (first use in this function)
g.c:14: error: (Each undeclared identifier is reported only once
g.c:14: error: for each function it appears in.)

#include <stdio.h>
#include <string.h>
main()
{
  FILE *myfileptr;
 char * fgets ( char * sc, int num, FILE * words );
 

  myfileptr=fopen("words","r");

    // gets() should be fgets. Please read the link posted for the function
  while((myfileptr=fgets(myfileptr))!=EOF)
  {
    if(sc)
      printf("%s",sc);
      printf("EOF\n");
     if(strlen(sc)%2==0) printf("Word not palindrom");
  else
  {
    int i;
    for(i = 0; i < strlen(sc); i += 1)
      if(sc[i] != sc[strlen(sc) - 1 - i])
      {
        printf("Word not palindrom");
        break;
      }

    if(i==strlen(sc)) printf("The word is palindrom");
  }
}
}

char * fgets ( char * sc, int num, FILE * words ); fgets is a standard function you don't need to prototype it. It is defined in stdio.h. while((myfileptr=fgets(myfileptr))!=EOF) fgets doesn't work like that.
A variable to hold the string needs to be declared first char buffer[ANYSIZE]; Then you can call fgets() fgets( buffer, sizeof buffer, myfileptr ); >g.c:14: error: 'sc' undeclared (first use in this function)
Isn't it obvious what it says? Where's sc declared before been used?

my error is now
g.c:12: warning: assignment from incompatible pointer type
if i do the follwing
fgets( buffer, sizeof buffer, myfileptr);
i get bus error
any ideas to fix the problem

#include <stdio.h>
#include <string.h>
main(char *sc)
{
  FILE *myfileptr;
 char * fgets ( char * sc, int num, FILE * words );
 char buffer[5456556];

  myfileptr=fopen("words","r");

    // gets() should be fgets. Please read the link posted for the function
  while(myfileptr=fgets( buffer, sizeof buffer, myfileptr));
  {
    if(sc)
      printf("%s",sc);
      printf("EOF\n");
     if(strlen(sc)%2==0) printf("Word not palindrom");
  else
  {
    int i;
    for(i = 0; i < strlen(sc); i += 1)
      if(sc[i] != sc[strlen(sc) - 1 - i])
      {
        printf("Word not palindrom");
        break;
      }

    if(i==strlen(sc)) printf("The word is palindrom");
  }
  }
  }

line 3: wrong function parameters. There are only two valid ways to code that function: int main(int argc, char* argv[]) int main() You will have to change all the lines that reference sc to use argv[1] instead. Or you could just add another variable and leave the rest of the code alone. const char* sc = argv[1]; line 6: delete it like Aia askied you to do.

line 12: change it like below because you are destroying the file pointer and remove the semicolon at the end of that line. while(fgets( buffer, sizeof buffer, myfileptr) != NULL)

ok thanks so much guys. now with the code below my error now is
it prints
EOF
bus error

char buffer[5456556];

when i delete the above file my errors are
g.c:13: error: 'buffer' undeclared (first use in this function)
g.c:13: error: (Each undeclared identifier is reported only once
g.c:13: error: for each function it appears in.)
which is this line

while(fgets( buffer, sizeof buffer, myfileptr) != NULL)

#include <stdio.h>
#include <string.h>
int main(int argc, char* argv[])
{
  FILE *myfileptr;
 char * fgets ( char * sc, int num, FILE * words );
 char buffer[5456556];
 const char* sc = argv[1];

  myfileptr=fopen("words","r");

    // gets() should be fgets. Please read the link posted for the function
 while(fgets( buffer, sizeof buffer, myfileptr) != NULL)
  {
    if(sc)
      printf("%s",sc);
      printf("EOF\n");
     if(strlen(sc)%2==0) printf("Word not palindrom");
  else
  {
    int i;
    for(i = 0; i < strlen(sc); i += 1)
      if(sc[i] != sc[strlen(sc) - 1 - i])
      {
        printf("Word not palindrom");
        break;
      }

    if(i==strlen(sc)) printf("The word is palindrom");
  }
  }
  }

you STILL are trying to define "fgets". fgets() is a standard library function, you do not need a prototype. that you're trying to do so, is at least part of your problem.

and do you REALLY want a character array ("buffer") to be 5 Megabytes in size??


.

aia i did as you said and i got
eof
bus error

Remove your version prototype of fgets.

[Edit: ]
Add a return to that main function.

If you don't start learning how to properly indent and use consistent spacing in your code:
1st you won't be able to see what you are doing.
2nd you are not going to make it.

Here's is an example of how your code might look properly indented and with a consistent spacing.

#include <stdio.h>
#include <string.h>

int main ( int argc, char *argv[] )
{
	FILE *myfileptr;

	char buffer[BUFSIZ];
	const char *sc = argv[1];

	myfileptr = fopen( "words","r" );

	while ( fgets( buffer, sizeof buffer, myfileptr) != NULL )
	{
		if ( sc )
			printf( "%s", sc );

		printf( "EOF\n" );

		if ( strlen( sc ) %2 == 0 )
			printf( "Word not palindrom" );
		else
		{
			int i;
			for ( i = 0; i < strlen( sc ); i += 1 )
				if ( sc[i] != sc[strlen( sc ) - 1 - i] )
				{
					printf( "Word not palindrom" );
					break;
				}

			if ( i == strlen( sc ) )
				printf( "The word is palindrom" );
		}
	}
	return 0;
}

const char *sc = argv[1]; argv[1] is suppose to be an argument given by the user through the command line. What if nothing is entered after the name of the program? myfileptr = fopen( "words","r" ); A file name words must exist in the same directory that the executable program. What if the file doesn't exist? while ( fgets( buffer, sizeof buffer, myfileptr) != NULL ) You keep reading from a file myfileptr( that it may or may not exist ) one buffer-size
at a time through the while loop, but you are doing nothing with what you read from the file
throughout your code. Instead you keep processing this sc that doesn't have anything with what is in the file, and again may not be even pointing to anything given at the command line.

I should stop at this point, until you get that.

If you don't start learning how to properly indent and use consistent spacing in your code:
1st you won't be able to see what you are doing.
2nd you are not going to make it.

3rd -- people here are going to get tired of looking at your posts and not bother to help you.

especially when it takes three times to tell you the same thing. i sure hope you take that fgets( ) prototype out before you post again.

This article has been dead for over six months. Start a new discussion instead.