String and character pointers
Ok im brand new to c . Been programing in delphi and stuff for a while but at the moment im just using nedit and cc in linux.
Im trying to write a program to read a file, and print out the links it has. Most of the code i have tested and works, the problem is the "p[0] = &a;" line. The idea behind it is, i want to shift the first character in the string up some after ive found a link, so it caries on from where it left off, rather than starting from the start and finding the same link each time.
Googled for a while but im totaly stumped this time!
Code:
#include <stdio.h>
#include <string.h>
void readfile(FILE *fp, char *p);
void findtag(char *p, char *start, char finish, char *result);
main(int argc, char *argv[])
{
FILE *fp;
char c[10000], tag[100];
if ((argc != 1) && ((fp = fopen(*++argv, "r")) != NULL))
{
readfile(fp,c);
fclose(fp);
while(c != '\0')
{
findtag(c,"<a",'>',tag);
printf("%s\n",tag);
/* findtag(tag,"href=",' ',tag); */
}
}
else
printf("Arf\n");
}
void readfile(FILE *fp, char *p)
{
int i;
i = 0;
while ((p[i++] = getc(fp)) != EOF)
;
p[i - 1] = '\0';
}
void findtag(char *p, char *start, char finish, char *result)
{
char *a;
int i;
i = 0;
a = strstr(p, start) + strlen(start);
if (a != '\0')
{
while ((result[i++] = *a++) != finish)
;
result[i-1] = '\0';
}
p[0] = &a;
}