How to convert char read from file into string
#include <stdio.h>
#include <errno.h>
#include <string.h>
int main(int argc, char **argv)
{
FILE *f;
int c;
errno = 0;
/Check for no. of arguments and try opening file/
if (argc == 1)
{
printf("There is no file selected.\n");
printf("Usage: test <filename> <filename> \n");
}
else
{
for (int i = 1; i < argc; i++)
{
if((f = fopen(argv[i], "r")) == NULL)
{
printf("File: %s cannot be opened. \n", argv[i]);
fprintf(stderr, "Open file %s failed: %s\n", argv[i], strerror(errno));
}
else
{
/read from text file as characters/
while ((c = fgetc(f)) != EOF )
{
if(c == '"')
{
while((c = fgetc(f)) != '"')
{
putc(c, stdout);
}
Hi there....the above is what I have got so far. It checks for the number of arguments and open the files specified. The it reads from the text files that the file is specified.
Objectives:
To read the contents of the file, check validity for absolute reference to a file ie. hypertext starting with file:/
eg <a href="file:/example">. Should be recursive as well
Questions:
I have managed to check for < > and read any text inside the < > but I need to extract anything that is after file:/. I tried using fgets as well...but I cant seems to filter out text that is after the file:/.
Any help, suggestions and comments are welcome as I am still new with C.
Thanks