Ok I started messing around with stuff and it works...with 7 warnings.
It still doesn't append the line char though. Here is the ugly freak of my programming
Code:
#include <stdio.h>
#include <string.h>
int searchnum = 0;
char getline[1000];
char *line[100];
char *lineh;
int linea[100];
main()
{
char search[20];//make a char for the search parameters
strcpy(search,"hi");//make search equal 'hi'
FILE *pfile;//make a file pointer
pfile = fopen("searchfile.txt","r");//open the file for reading
printf("searchtext: %s ",search);//show the user what is being searched for
if (pfile == NULL)//if the file does not exist...
{
printf("file does not exist, you fail");//... tell the user he is a fail :D
getch();//get a message from the keyboard then end the program
return 0;//tell there were no errors
}
else//if the file does exist...
{
while((lineh=fgetc(pfile)) != EOF)//...read it one character at a time
{
printf("\nlineh at top:%c",lineh);//see what the program gets here to see if it taking
//the right path
if (isspace(lineh))//if the character is a whitespace...
{
if (strcmp(line,search) == 0)//...see if it equals what we are searching for
{
searchnum + 1;//if it does equal what we want add one
//to searchnum
printf("found %d\n",searchnum);//tell the user we found
//hi once
strcpy(line,"");//erase everything in line
}
else
{
printf("space");
strcpy(line,"");
}
}
else//if the character isn't a whitespace add to the line
{
printf("\nlineh else: %c\n",lineh);//show what lineh equals
lineh = linea;
printf("linea:%c",linea);
strcat(lineh,line);//append line to accomodate lineh
printf("\nline: %s",line);//tell the user what is in line at the moment
}
}
printf("%d",searchnum);//after the loop tell how many 'hi's were found
getch();//get input from the keyboard then quit
}
}
Can you see what I am doing wrong, thanks.