• 0

Help with C


Question

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

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.