First time poster here. I am relatively new to programming and I require assistance in a program I'm trying to code. Bear with me for a minute or two.
Basically this program receives a text file and an operator (m2M or M2m) as an argument, changes lower case to upper case (correction - depending on the operator changes from lower to upper case or from upper to lower) and then writes the text in another text file. Let's not focus on this last part for now.
This is the code I have so far:
Code:
int main (int argc, char **argv)
{
FILE*f1, *f2;
char texto[500][1000];
int L, i;
if(argc!=4)
{
help(); //this function is written on the actual code, but I didn't want to include it here as it's not important for this thread
return -1;
}
if((strcmp(argv[1], "M2m")!=0)&&(strcmp(argv[1], "m2M")!=0))
{
printf("Operador mal inserido!");
help();
return -1;
}
f1=fopen(argv[2], "rt");
for(L=0; fgets(texto[L],1000,f1)!=NULL;L++);
for(i=0; i<=strlen(*texto); ++i)
{
if((texto[i]>97)&&(texto[i]<=122))
texto[i]=texto[i]-32;
else
texto[i]=texto[i]+32;
}
for(i=0;i<1001;++i)
printf("%s", texto[i]); //this is purely to test the string, later I'll change it to a fprintf to the file f2
fclose(f1);
return 0;
}
It's the second "for" that's giving me troubles. I can guess why that's wrong, but I don't really know how to fix it. Any suggestions/fixes?
Thanks in advance.
Edit: in the part of the code where upper case are changed to lower case and vice versa i forgot something. The goal of the program is to let the user choose if he wants to change everything to upper or everything to lower. That code part needs a
Code:
if(strcmp(argv[1],"m2M")==0)
...
else