I have a file called dvwl.c, and I am running it on a putty (unix server) using:
gcc -Wall -g -o mycode dvwl.c
./mycode 1 /usr/share/dict/words s
What it does is, it opens up words (since i gave that path) and reads the lines skipping the first line (since it says 1, if i put here 3, then it would skip the first 3 lines), then it is supposed to print the lines with all vowels removed (small or big, and not y/Y) and some other character as an argument (i put s for this). So it now print them with all vowels and s removed.
But I get these errors:
dvwl.c: In function �replace�:
dvwl.c:5: warning: implicit declaration of function �tolower�
dvwl.c:6: warning: implicit declaration of function �toupper�
dvwl.c: In function �main�:
dvwl.c:15: error: �try� undeclared (first use in this function)
dvwl.c:15: error: (Each undeclared identifier is reported only once
dvwl.c:15: error: for each function it appears in.)
dvwl.c:15: error: expected �;� before �{� token
dvwl.c:31: warning: control reaches end of non-void function
What is wrong with my code? Also what is perror and how do I properly use it, and do i need an exit(1); after i use perror? Also what is wrong with my try/catch?
#include<stdio.h>
void replace(char *s,char v) {
while (*s) {
if ((char)*s!='a' && (char)*s!='e' && (char)*s!='i' && (char)*s!='o' && (char)*s!='u' && (char)*s!=tolower(v)) {
if ((char)*s!='A' && (char)*s!='E' && (char)*s!='I' && (char)*s!='O' && (char)*s!='U' && (char)*s!=toupper(v)) {
printf("%c", *s);
}
}
s++;
}
}
int main(int argc, char **argv) {
try {
int g=1;
char line[30];
FILE *fr = fopen (argv[2], "r");
while(fgets(line,30,fr)!=NULL) {
if (g++>atoi(argv[1])) {
replace(line,'s');
}
}
fclose(fr);
}
catch(Exception e) {
perror("Usage: %s %s\n",argv[0] ,argv[1]);
exit(1);
}
return 0;
}