mik Posted September 27, 2004 Share Posted September 27, 2004 I'm just learning C and having a little trouble. I have my program reading in characters from a file, and outputting them to another file, as well as recording two words from the commandline. ie A2 java C <input >output The program has to find any instance of the first one and replace it with the second one. For example. If the input file contained "I love java". The output file would now have "I love C". Heres what I have so far. I just dont know where to go from here. Help would be greatly appreciated. I know theres some great programmers out there who could do this in no time at all. Thank you. #include <stdio.h> #include <ctype.h> #define MAX 80 int main(int argc, char* argv[]) { const char* old = argv[1]; const char* new = argv[2]; int i = 0; int c; char list[MAX]; while ((c = getchar()) != EOF) { list = c; putchar(list); i++; } return 0; } Link to comment Share on other sites More sharing options...
0 kjordan2001 Posted September 27, 2004 Share Posted September 27, 2004 Just so you know, you're heading for a buffer overflow there if i goes past 79. But I guess what you want help with is searching for java and replacing it with C? Link to comment Share on other sites More sharing options...
Question
mik
I'm just learning C and having a little trouble.
I have my program reading in characters from a file, and outputting them to another file, as well as recording two words from the commandline.
ie
A2 java C <input >output
The program has to find any instance of the first one and replace it with the second one.
For example. If the input file contained "I love java". The output file would now have "I love C".
Heres what I have so far. I just dont know where to go from here.
Help would be greatly appreciated. I know theres some great programmers out there who could do this in no time at all.
Thank you.
#include <stdio.h>
#include <ctype.h>
#define MAX 80
int main(int argc, char* argv[]) {
const char* old = argv[1];
const char* new = argv[2];
int i = 0;
int c;
char list[MAX];
while ((c = getchar()) != EOF) {
list = c;
putchar(list);
i++;
}
return 0;
}
Link to comment
Share on other sites
1 answer to this question
Recommended Posts