Monday, May 24, 2010

Need help with c-programming; strsr and other?

Write a function that takes as input a string containing HTML source code and returns both the # of images referenced in the code and the total screen area (in square pixels) occupied by the images


The function MUST have the following declarationint estImageContent(char *pacHTML, long int *pliArea);








1. Prompt the user for an input filename


2. Open the file, read its contents into a string (up to 20000 bytes), close file


3. Call estImageContent()


4. Print the following to the screen:


1. Input filename


2. Estimated # of images


3. Estimated total screen area in square pixels


5. Loop back to prompt





this is what i have so far


/* the first thing i did was uppercase*/





#include %26lt;stdio.h%26gt;


#include %26lt;string.h%26gt;


#include %26lt;ctype.h%26gt;








void fileToString(char filename[], char theString[]);


char *upperCaseTheString(char *pc);





int main()


{


char filename[] = "p6in1.txt";


char theString[20000] = "";





fileToString(filename, theString);


upperCaseTheString(theString);





printf("%s", theString);





return (0);


}








void fileToString(char filename[], char theString[]) {


FILE *fp;


char buf[BUFSIZ+1];





fp = fopen(filename, "r");





while (fgets(buf, BUFSIZ, fp) != NULL) {


strcat(theString, buf);


}





fclose(fp);





}








char *upperCaseTheString(char *pc) {


char *pcReturn = pc;





while (*pc != '\0') {


*pc = toupper(*pc);


pc++;


}





return pcReturn;


}


fp=fopen("p6in.txt","r");





if(fp==NULL)


{


printf("\n\t\tSORRY......\n\t\t CANNOT OPEN FILE\n");


return 0;


}





printf("\n\t\tFILE data.txt FOUND!\n");


printf("\n\nSearch what string?\t");


gets(str1);





while ((fgets( str2, 100, fp )) != NULL) //not the end of file


{


if (strcmp(str1, str2)


iCount++;











}


printf("\n%d OCCURRENCES OF STRING %s FOUND", iCount ,str1);








}

Need help with c-programming; strsr and other?
Here is a link with info about strstr:


http://www.cppreference.com/stdstring/st...
Reply:I don't know

customer satisfaction survey

No comments:

Post a Comment