Thanks for at least reading.

My assignment is to prompt for a filename, change the contents to caps, and print. I have the following, and it's giving me the error at line 25 (the inside loop)

Assignment makes integer from pointer without a cast

What does that mean, and how can I get rid of it?

#include<stdio.h>
#include<stdlib.h>


int filechar(char []);

int main()

{
	
	FILE *inFile;
	
	char filename[13], line[256];

	int numchar, i;
	
	printf("Please enter the name of the file you wish to open:");
	
	gets(filename);

	inFile=fopen(filename, "r");
	
	while (fgets(line,256,inFile) != NULL)
	
		for (i = 0; line[i] = NULL; i++);
			line[i] = toupper(line[i]);
			
	
	fputs(line, inFile);
	
	printf("%s\n", line);
	
	fclose(inFile);
	

	
	

	return 0;
}

Mistake:

for (i = 0; line[i] = NULL; i++);

1>Remove the semicolon at the end of this statement.
2>It should be line!=NULL and not line=NULL.

Member Avatar for iamthwee

You shouldn't use gets()
http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1049157810&id=1043284351

So a solution would be:
http://www.daniweb.com/tutorials/tutorial45806.html

It seems like a bit too much effort but in the end it's worth the good habits.

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

int main(void)
{
    
   char text[20];
   fputs("Please enter the name of the file you wish to open:", stdout);
   fflush(stdout);
   if ( fgets(text, sizeof text, stdin) != NULL )
   {
      char *newline = strchr(text, '\n'); /* search for newline character */
      if ( newline != NULL )
      {
         *newline = '\0'; /* overwrite trailing newline */
      }
   }
    
  FILE *fp;
  char buf[BUFSIZ] = "";
  int i;
  
  if ((fp = fopen(text, "r")) == NULL)
  {
    perror (text);
    return (EXIT_FAILURE);
  }
  
  i = 0;

  while (fgets(buf, sizeof(buf), fp) != NULL)
  {
    int k = strlen(buf);
    
    int m;
    for ( m = 0; m < k; m++ )
    {
     printf("%c",toupper(buf[m]));
    }
      
    i++;
  }
  
  fclose(fp);
  getchar();
  return(0);
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.