thank you for quick replay
Quote:
Originally Posted by
Adak
You could put this string into a char array and then scan through each char. The equal sign precedes the info you want written out to a file. So when the letter you're looking at is an equal sign, you know that you need to write out the next several char's, until you reach the colon, which marks the end of the field.
What part are you stuck on? Show me your code to handle this, and explain your specific troubles, please.
Adak
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
and compile
gcc one.c -o one `pkg-config gtk+-2.0 --cflags --libs`
i used some gtk functions here.
i know now you are clear about this
please help me
thank you in advance
thank you for quick replay
Quote:
Originally Posted by
KONI
You're already using
strtok() but unfortunately only with the '\n' delimiter. Instead, why don't you use it a little more advanced:
1. split your input using the delimiter ':', this will give you a sequence of "option=value" items (as long as neither option nor value contains the ':').
2. split your sequence of "option=value" with the delimiter '=' which will give you the 2 items option and value
3. print the value corresponding to your options.
The whole thing shouldn't take more than .... 10 lines max.
no am unable to write the code in 10 lines
can anybudy rewrite the code please
thank you in advance
thank you for quick replay
Quote:
Originally Posted by
Adak
No, I couldn't write the program, I don't use that compiler and don't have those header files. More importantly, you get better at programming if you practice - like anything else.
I know it's time consuming and it can be frustrating, but I believe you have two ways of doing this program, laid out before you.
Adak
thank you for boosting.
i succeeded.
but still having a problem
it will not printing
fist "five"(i.e. 123),and it is printing remaining "five".
whats the problem.
can you please help me .
thank you in advance
thank you for quick replay
sorry.
i forgot some code.
actually this is the response
there is an extra ":" in first line so,
the first "five"(i.e. 666) is not printing.
can you please help me in this way
thank you in advance