doubt in string manipulation

punith's Avatar, Join Date: Sep 2007
Go4Expert Member
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 =
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's Avatar, Join Date: Dec 2006
Team Leader
Use strcat or strncat, and dereference the pointer. You don't show enough code for me to give you an example.
punith's Avatar, Join Date: Sep 2007
Go4Expert Member
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;

Last edited by shabbir; 17Sep2007 at 20:28.. Reason: Code block