Code:
if (argc==2)
{
infiled = open(argv[argc-1], O_RDONLY, 0);
}
if (infiled == -1)
{
printf("%s cannot be opened\n", argv[argc-1]);
}
else
{
char *position = strchar(infiled, '¥');
if (position)
{
nwrite = open(position-infiled, O_CREAT, 0);
}
}
You're trying to use strchr() with a file pointer. It won't work (at least, not in my compiler). It requires a pointer to a string (a char array will do), but not a file pointer.
So, you need to do some looping and take the rows of text into a char array, and nothing does that as nicely as fgets(buffer, sizeof(buffer), filePointer);
Then have strchr() check each buffer.
and loop back for the next row of text, etc.
Code:
while((fgets(buffer, sizeof buffer, filePointer)) != NULL) {
//rest of your code in here
}
Is a good way to go, imo.