This program is supposed to replace & with & and < with < and > with > and " with " or at least that is my understanding of what the question is asking. It must use the header provided. I wrote this code, but it returns the wrong results or just the first character.
Sorry for the some what confusing way of the program, any help would be greatly appreciated.
Code:char * toHTML(const char *src){ int n=0; int size=0; int i=0; int t=0; size=strlen(src); n=size; int totalchanges=0; int changes=0; int factorA= 5-1; int factorB= 4-1; int factorC= 4-1; int factorD= 6-1; for(i=0; i<n; i++) { if(src[i] == '&') { changes++;}} totalchanges=(changes)*(factorA); changes=0; for(i=0; i<n; i++) { if(src[i] == '<') { changes++;}} totalchanges+=(changes)*(factorB); changes=0; for(i=0; i<n; i++) { if(src[i] == '>') { changes++;}} totalchanges+=(changes)*(factorC); changes=0; for(i=0; i<n; i++) { if(src[i] == '"') { changes++;}} totalchanges+=(changes)*(factorD); size+=totalchanges; char *result = NULL; result = malloc(sizeof(char) * (size + 1)); for(i=0; i<n; i++){ if(src[i] == '&') {//& result[t]='&'; result[t+1]='a'; result[t+2]='m'; result[t+3]='p'; result[t+4]=';'; t+=4;} if(src[i] == '<') { result[t]='&'; result[t+1]='l'; result[t+2]='t'; result[t+3]=';'; t+=3;} if(src[i] == '>') { result[t]='&'; result[t+1]='g'; result[t+2]='t'; result[t+3]=';'; t+=3;} if(src[i] == '"') { result[t]='&'; result[t+1]='q'; result[t+2]='u'; result[t+3]='o'; result[t+4]='t'; result[t+5]=';'; t+=4;} if((src[i] != '&')&& (src[i] != '<')&& (src[i] != '>')&& (src[i] == '"')){ result[t]=src[i];} t++; } return result; }