Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   doubt in string manipulation (http://www.go4expert.com/forums/doubt-string-manipulation-t6392/)

punith 17Sep2007 16:37

doubt in string manipulation
Hi all

Since i am more conversant with assembly programming my knowledge in c
is very limited . Just have a small boubt

there is a function createEAPfile( char *IMSI)
now i have to create a disk resident file which should look like the following

User-Name = "eapsim"
NAS-IP-Address = marajade.sandelman.ottawa.on.ca
EAP-Code = Response
EAP-Type-Identity = "eapsim"
Message-Authenticator = 0
NAS-Port = 0

Here i have to update the User-Name with the value present in *IMSI
IMSI=102AD456780 but at the same time i should have double quotes too

i tried the following

char *p = "User-Name = \"IMSI\"";
but output is
User-Name = "IMSI"
but what i want is
User-Name = "102AD456780"

how to get this value of IMSI insted of printing IMSI itself.

Thanks in advance;


DaWei 17Sep2007 18:25

Re: doubt in string manipulation
Use strcat or strncat, and dereference the pointer. You don't show enough code for me to give you an example.

punith 17Sep2007 18:49

Re: doubt in string manipulation
Ya got it DaWei thanks a lot


#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main()
 int fd1,fd2,nread;
char buf[1024],
char *string= "User-Name = \"";
char *string1,*IMSI="eapsim";

        string1 = malloc (strlen (string)+strlen( IMSI)+1);
        strcat (string1,string);
        strcat (string1,IMSI);
        strcat (string1,"\"");
        strcat (string1,"\n");
      write (1,string1,strlen(string1));
return 0;

All times are GMT +5.5. The time now is 13:56.