I have to read a file from a command line argument. The file has a string that the program reads and reverses. The reversed code is then transformed into a new string by changing the characters in that string by reading the characters one by one.
I'm getting these errors when I compile:
-conflicting types for 'reverse'
-previous implicit declaration of reverse was here -> this is when I call "reverse(string);"
-previous implicit declaration of append was here -> this is when I call append similar to reverse
Lastly I want "?" to turn into 3F% and I cant append % somehow. It gives out something weird.
EDIT: Thank you so much for the help guys. But, when I do "append(string,'%')" it starts printing several random characters and printing wrong stuff.
#include <string.h>
#include <stdio.h>
int main(int argc, char **argv)
{
FILE *fp;
char input;
char string[100];
int change = 1;
int capA = 65;
int capZ = 90;
int lowera = 97;
int lowerz = 122;
int c;
fp = fopen(argv[1], "r");
while ((c = fgetc(fp)) != EOF)
{
if(c == '_' || c == '?' || c == ':' || c == '/' || c == '&' || c == ' ')
{
if(c == '?'){
append(string,'3');
append(string,'F');
append(string, "%%");
}
change = 0;
}
else if(c >= capA && c <= capZ)
{
append(string,tolower(c));
change = 0;
}
else if(c >= lowera && c <= lowerz)
{
append(string,toupper(c));
change = 0;
}
else if(c >= '?' && c <= '?')
{
append(string,c);
change = 0;
}
else
{
append(string,c);
change = 0;
}
}
fclose(fp);
reverse(string);
printf(string);
}
void reverse(char *string)
{
int length, c;
char *begin, *end, temp;
length = string_length(string);
begin = string;
end = string;
for ( c = 0 ; c < ( length - 1 ) ; c++ )
end++;
for ( c = 0 ; c < length/2 ; c++ )
{
temp = *end;
*end = *begin;
*begin = temp;
begin++;
end--;
}
}
int string_length(char *pointer)
{
int c = 0;
while( *(pointer+c) != '\0' )
c++;
return c;
}
void append(char* s, char c)
{
int len = strlen(s);
s[len] = c;
s[len+1] = '\0';
}