So here is my code:
The purpose of this code is to take all the plain text in all capital letters in
the vitranc.txt file and turn them all in to lowercase characters.

Now to my knowledge i can do this with "tolower" function but:
when i add tolower in my "while" counter it does not compile but gives an error
about some conversion from char to int.

Now in addition i have also tried turning the "lists" to int whit "atoi" method before
passing it on to "tolower" and it works but not as it should only few words get turned
to lowercase but most remain uppercase.

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

int main(){

	FILE *open;
	open = fopen("vitranc.txt","r");

	char lines[300];
	
	while(!feof(open)){
		fgets(lines,300,open);
		lines = tolower(atoi(lines));
	        printf("%s",lines);
	}
	printf("\n\n");

	fclose(open);

}

Instead of a while counter i have tried a "for" expression in this way:

char lines[300];
int i;

for(i=0;lines[i],i++){
    lines[i] = tolower(lines[i]);
    printf("%s",lines);
}

The reason is failing to compile is this line of code.

lines = tolower(atoi(lines));

which should be

lines[index_value] = tolower(lines[index_value]);

Edited 5 Years Ago by gerard4143: n/a

Here's your code cleaned up a little, please reads the comments.

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

int main()
{

  FILE *open = NULL;/*all variables should defined at the start of the block*/
  int i = 0;
  char lines[300];
  
  if (!(open = fopen("vitranc.txt","r")))/*check to see if fopen failed*/
  {
    fputs("could not open file!\n", stderr);
    exit(EXIT_FAILURE);
  }

  while( true )
  {
    fgets(lines,300,open);
    
    if (feof(open)) break;
    
    for (i = 0; i < strlen(lines); ++i)
      lines[i] = tolower(lines[i]);
    
    printf("%s",lines);
  }
  printf("\n\n");

  fclose(open);
  
  return 0;/*main returns an int*/
	
}
This article has been dead for over six months. Start a new discussion instead.