Thread: converting string into array

  1. #1
    Registered User
    Join Date
    Jul 2022
    Posts
    50

    converting string into array

    im trying to convert a string into an array


    cint1 is "1abcd" (char)

    Code:
        char archar[] = {cint1};
    
    
        printf("%s", archar[0]);
    the entire code is:

    Code:
        int int1;
    
    
        char char1[30] = "a";
        char char2[30] = "b";
        char char3[30] = "c";
        char char4[30] = "d";
    
    
        char cint1[40] = "";
        int1 = 1;
    
    
    
    
        itoa(int1,cint1,10);
    
    
    
    
        strcat(char1,char2);
        strcat(char1,char3);
        strcat(char1,char4);
    
    
        strcat(cint1,char1);
    
    
    
    
        printf("%s",cint1);
    
    
        char archar[] = {cint1};
    
    
        printf("%s", archar[0]);
    Last edited by WaterSerpentM; 10-15-2023 at 06:59 PM.

  2. #2
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,112
    This is so wrong! You really need to study a good up to date book on the C Programming Language rather than try to hack your way trying to use a non-standard function in such a ridiculous way!

    When I am near my computer later I will explain further.

  3. #3
    Registered User
    Join Date
    Jul 2022
    Posts
    50
    ive figured it out

    Code:
    char my_string[] = {""};
    
    strcpy (cint2,my_string);

  4. #4
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,112
    Quote Originally Posted by WaterSerpentM View Post
    ive figured it out

    Code:
    char my_string[] = {""};
    
    strcpy (cint2,my_string);
    No, you didn't! Will respond later.

  5. #5
    Registered User
    Join Date
    Jul 2022
    Posts
    50
    Quote Originally Posted by rstanley View Post
    No, you didn't! Will respond later.
    ye you're right, it outputs a blank line

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Converting a string into an array?
    By litzkrieg in forum C Programming
    Replies: 2
    Last Post: 04-06-2011, 05:32 PM
  2. Converting a string into an array?
    By litzkrieg in forum C Programming
    Replies: 1
    Last Post: 04-06-2011, 05:32 PM
  3. Converting a string into an array?
    By litzkrieg in forum C Programming
    Replies: 4
    Last Post: 04-06-2011, 05:29 PM
  4. converting a string to array
    By jtieu in forum C++ Programming
    Replies: 8
    Last Post: 03-28-2011, 11:27 PM
  5. converting a string to an array
    By curlyfries in forum C Programming
    Replies: 25
    Last Post: 11-14-2010, 04:39 AM

Tags for this Thread