1

I want the user to be able to type

start < read_from_old_file.c > write_to_new_file.c 
//or whatever type of file

So once the user types the command "start" followed by a "<", this will indicate reading a file, whereas ">" will indicate writing to a new file.

Problem is, I know you can use

scanf("%s", buff);

But this would read one word and not go onto the next.

Ave
  • 107
  • 2
  • 2
  • 8
  • 3
    Use `fgets()` to read the whole line, and `strtok()` to find the words. – Barmar Apr 30 '15 at 00:37
  • 2
    Use [`fgets()`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/fgets.html) or [`getline()`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/getline.html) to read lines. See also [How to use `sscanf()` in loops?](http://stackoverflow.com/questions/3975236) – Jonathan Leffler Apr 30 '15 at 00:45

2 Answers2

0

You can use:

scanf("%[^\n]%*c",buff);

If you wish to use scanf() for this.

%*c is to get rid of the newline due to hitting enter.

Jahid
  • 21,542
  • 10
  • 90
  • 108
0

In general, using the scanf family of functions is a bad idea. Instead, you should use fgets or fread to read in data, then perform your own processing on it. fgets will read a line at a time, whereas fread is for when you don't care about lines and just want n bytes of data (good for, say, implementing cat).

Most programs will want to read a line at a time. You'll need to allocate your own buddy to pass to fgets.

Functino
  • 1,939
  • 17
  • 25