Code:
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <linux/sockios.h>
#include <string.h>
#include <math.h>
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <syslog.h>
#include <stdio.h>
void write_data();
void write_data()
{
char *response="ID=123:one=a:[email protected]:three=:four=456:five=\nID=123:one=aa:[email protected]:three=22222222:four=:five=0000000000\n:/";
FILE *appenddatabase;
char appendfile[256];
char tempfile[256] = "/root/Desktop/1234/MyFriends.txt";
appenddatabase = fopen(tempfile, "r");
if (appenddatabase == NULL)
appenddatabase = fopen(tempfile, "w");
char *delims="\n";
char *result = NULL;
result = strtok(response,"\n");
printf( "refresh Contact response %s\n",response);
int count=0;
while(result!= NULL ) {
count=count+1;
if(strstr(result,":/")!=NULL) {result=NULL;continue;}
if(count>0)
{
char **ref;
int j;
ref=g_strsplit(result,":",-1);
char *one="",*two="",*three="",*four="",*five="";
for(j=0;j<7;j++)
{
if(strstr(ref[j],"one")!=NULL)
{
char **split1;
split1=g_strsplit(ref[j],"=",2);
one=split1[1];
printf("%s\n",split1[1]);
}
else if(strstr(ref[j],"two")!=NULL)
{
char **split2;
split2=g_strsplit(ref[j],"=",2);
printf("%s\n",split2[1]);
two=split2[1];
}
else if (strstr(ref[j],"three")!=NULL)
{
char **split5;
split5=g_strsplit(ref[j],"=",2);
printf("%s\n",split5[1]);
three=split5[1];
}
else if(strstr(ref[j],"four")!=NULL)
{
char **split4;
split4=g_strsplit(ref[j],"=",2);
printf("%s\n",split4[1]);
four=split4[1];
}
else if(strstr(ref[j],"five")!=NULL)
{
char **split3;
split3=g_strsplit(ref[j],"=",2);
printf("%s\n",split3[1]);
five=split3[1];
}
else {}
}
fprintf(appenddatabase, "__BEGIN_\n");
fprintf(appenddatabase, "%s\n", one);
fprintf(appenddatabase, "%s\n", two);
fprintf(appenddatabase, "%s\n", three);
fprintf(appenddatabase, "%s\n", four);
fprintf(appenddatabase, "%s\n", five);
}
result = strtok( NULL, delims );
}
fclose(appenddatabase);
}
int
main(int argc, char *argv[])
{
gtk_set_locale ();
gtk_init (&argc, &argv);
write_data();
gtk_main ();
return 0;
}
save it as one.c