I am writing some string to a gstring using printf as:
char *string<i>
/*where string<i> stands for string1, string2
and so on*/
g_string_append_printf (ustring, "@%s{%s,\n",string1, string0);
if( strlen(string2)!=0 ||string2!=NULL)
g_string_append_printf (ustring,"\tAuthor=\"%s\",\n", string2);
if( strlen(string3)!=0 ||string3!=NULL)
g_string_append_printf (ustring,"\tYear=\"%s\",\n", string3);
if( strlen(string4)!=0 ||string4!=NULL)
g_string_append_printf (ustring, "\tTitle=\"%s\",\n", string4);
GLib's are probably not exactly important here. Consider it as
printf ("\tAuthor=\"%s\",\n", string<i>)
When this works rather fine, it seems not the best way(i have strings string<1> to string<30>) and I am looking for some better way.
Points to consider
Any string may be empty/NULL, as checked by every line before the printf.
Would be better if the complete print thing works as a function
Any better way of implementing this?