1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

doubt in string manipulation

Discussion in 'C' started by punith, Sep 17, 2007.

  1. punith

    punith New Member

    Joined:
    Sep 4, 2007
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    ALP programmer
    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
    say
    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;

    regards
    Punith
     
  2. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    Use strcat or strncat, and dereference the pointer. You don't show enough code for me to give you an example.
     
  3. punith

    punith New Member

    Joined:
    Sep 4, 2007
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    ALP programmer
    Ya got it DaWei thanks a lot

    Code:
    #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 a moderator: Sep 17, 2007

Share This Page