I apologize in advance for any orthographic or grammatical error due to the fact that English is not my mother tongue.
I'm new to HTML and I've made a C program to automate a repetitive encoding (creating button spoilers, asking for the hidden content and what's written on the button each time)
The thing is that I've been forced to convert all the text (array of char) I wanted to write in hexadecimal because it contained some of the reserved characters of C language...
The program runs smoothly and fits my needs for the moment but I'd like to know if there is another way than converting everything into hex.
Also, gcc gives me this warning twice :
format ‘%s’ expects argument of type ‘char ’, but argument 2 has type ‘char ()[50]’ [-Wformat]
after these kinds of lines :
scanf("%s", &hidden_text);
(hidden_text is an array of char
initialized like :
char hidden_text[50];)
how do I fix that warning ? passing a %50s
to scanf
didn't work (the program ran but this warning bothers me and I'd be glad if anyone tell me a way out of it)
If anyone see a way of upgrading that program or have any hint, please help out the new programmer I am.
(just for the record, I'm using linux, Emacs is my IDE and I'm using gcc to compile)
Here is the source code (hope I don't get reported for posting too much text):
#include<stdlib.h>
#include<stdio.h>
#include<string.h> /*strlen use this*/
int number_of_spoilers=10; /* the number of spoiler buttons you want to create (changed that value so you can test fast)*/
int a=0;
int spoiler=0; /*the spoiler Id I need to pass between each part*/
char part0[14]="\x3c\x68\x74\x6d\x6c\x3e\x0d\x0a\x3c\x62\x6f\x64\x79\x3e";
char part1[9]="\x3c\x64\x69\x76\x20\x69\x64\x3d\x22";
char part2[23]="\x22\x20\x73\x74\x79\x6c\x65\x3d\x22\x64\x69\x73\x70\x6c\x61\x79\x3a\x6e\x6f\x6e\x65\x22\x3e";
char hidden_text[50];
char part3[100]="\x3c\x2f\x64\x69\x76\x3e\x3c\x62\x75\x74\x74\x6f\x6e\x20\x74\x69\x74\x6c\x65\x3d\x22\x43\x6c\x69\x63\x6b\x20\x74\x6f\x20\x73\x68\x6f\x77\x2f\x68\x69\x64\x65\x20\x63\x6f\x6e\x74\x65\x6e\x74\x22\x20\x74\x79\x70\x65\x3d\x22\x62\x75\x74\x74\x6f\x6e\x22\x20\x6f\x6e\x63\x6c\x69\x63\x6b\x3d\x22\x69\x66\x28\x64\x6f\x63\x75\x6d\x65\x6e\x74\x2e\x67\x65\x74\x45\x6c\x65\x6d\x65\x6e\x74\x42\x79\x49\x64\x28\x27";
char part4[53]="\x27\x29\x20\x2e\x73\x74\x79\x6c\x65\x2e\x64\x69\x73\x70\x6c\x61\x79\x3d\x3d\x27\x6e\x6f\x6e\x65\x27\x29\x20\x7b\x64\x6f\x63\x75\x6d\x65\x6e\x74\x2e\x67\x65\x74\x45\x6c\x65\x6d\x65\x6e\x74\x42\x79\x49\x64\x28\x27";
char part5[51]="\x27\x29\x20\x2e\x73\x74\x79\x6c\x65\x2e\x64\x69\x73\x70\x6c\x61\x79\x3d\x27\x27\x7d\x65\x6c\x73\x65\x7b\x64\x6f\x63\x75\x6d\x65\x6e\x74\x2e\x67\x65\x74\x45\x6c\x65\x6d\x65\x6e\x74\x42\x79\x49\x64\x28\x27";
char part6[27]="\x27\x29\x20\x2e\x73\x74\x79\x6c\x65\x2e\x64\x69\x73\x70\x6c\x61\x79\x3d\x27\x6e\x6f\x6e\x65\x27\x7d\x22\x3e";
char button_text[50];
char part7[9]="\x3c\x2f\x62\x75\x74\x74\x6f\x6e\x3e";
char part_end[16]="\x3c\x2f\x68\x74\x6d\x6c\x3e\x0d\x0a\x3c\x2f\x62\x6f\x64\x79\x3e";
FILE *f=NULL;
main(FILE *f)
{
f=fopen("/home/Spoilers.html","a");
if(f==NULL)
printf("Can't open file");
else{
fwrite(part0, sizeof(char), 14,f);
while(a!=number_of_spoilers){
printf("%s","button text ? :");
scanf("%s", &button_text);
printf("%s", "hidden text ? :");
scanf("%s", &hidden_text);
fwrite(part1, sizeof(char), 9,f);
char hex[5];
sprintf(hex, "%x", spoiler); /*change the spoilerId value to hexa*/
fwrite(&hex, sizeof(char), strlen(hex),f);
fwrite(part2, sizeof(char), 23,f);
fwrite(hidden_text, sizeof(char), strlen(hidden_text),f);
fwrite(part3, sizeof(char), 100,f);
fwrite(&hex, sizeof(char), strlen(hex),f);
fwrite(part4, sizeof(char), 53,f);
fwrite(&hex, sizeof(char), strlen(hex),f);
fwrite(part5, sizeof(char), 51,f);
fwrite(&hex, sizeof(char), strlen(hex),f);
fwrite(part6, sizeof(char), 27,f);
fwrite(button_text, sizeof(char), strlen(button_text),f);
fwrite(part7, sizeof(char), 9, f);
a=a+1; spoiler=spoiler+1;
}
fwrite(part_end, sizeof(char), 16,f); /*contain "</body></html>"*/
fclose(f);
}
}
Thanks by advance and have a good day (or night) !!