Having command line displayed in output
Hey guys: What i am trying to do is have an element in the command line effect my output.
For example:
In the command line i say:
cutchar - 2 -6 < theFileName
so then when i run a textfile, it removes columns 2 to 6
What am i doing wrong?
Here's how the text file looks:
Quote:
123456789123456789123456789
123456789123456789123456789
123456789123456789123456789
123456789123456789123456789
123456789123456789123456789
123456789123456789123456789
123456789123456789123456789
123456789123456789123456789
123456789123456789123456789
123456789123456789123456789
123456789123456789123456789
123456789123456789123456789
123456789123456789123456789
Here's my source code. It has something to do with under scanf
Code:
include <stdio.h>
#include <string.h>
int main(int argc, char ** argv)
{
int i, j=0;
char *token;
char c;
int range[10];
for(i=1;i<argc;i++)
{
token=strtok(argv[i]+1, "-");
while (token != NULL)
{
range[j++] = atoi(token);
token=strtok(NULL, "-");
}
}
for (i=0;i<j;i++)
{
if(i==0)
printf("Range from column: ");
else
printf("\t to column: ");
printf("%d", range[i]);
}
printf("\n");
i=0;//i is then returned
while (scanf("%c",&c) != EOF)
{
if (i < range[0] || i> range[1])
printf("%c", c);
printf("%c", argv);
}
return 0;
}
help would be appreciated.