Thread: A way to printf out in printf?

  1. #1
    Registered User
    Join Date
    Aug 2019
    Posts
    9

    A way to printf out in printf?

    Hello,

    is there a way to printf out.

    what i want is explode (" ") into 1 line and no spaces.
    i'll explode it with ("_")
    Code:
    int contents = 0;
    const char *setexplodetoname[] = {};
    
    char st[] = "Where there is will there is a way.";
    char *ch;
    ch = strtok(st, " ");
    while (ch != NULL)
    {
        printf("%s\n", ch);
        setexplodetoname[contents] = ch;
        contents++;
        ch = strtok(NULL, " ");
    }
    
    for (int i = 0; i < contents; i++)
    {
        printf("works.......\n");
        printf("%p\n", &setexplodetoname[i]);
    }
    i got this here output:
    Code:
    works.......
    0x7ffe381fa880
    works.......
    0x7ffe381fa888
    works.......
    0x7ffe381fa890
    works.......
    0x7ffe381fa898
    works.......
    0x7ffe381fa8a0
    works.......
    0x7ffe381fa8a8
    works.......
    0x7ffe381fa8b0
    works.......
    0x7ffe381fa8b8
    i except to get the name of explode below works....)

    Edit 17.25

    Thanks for helping me
    Last edited by 007fred50; 08-18-2019 at 09:25 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Do you want us to guess (again) what all the missing things are in your code snippet?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Aug 2019
    Posts
    9
    Hello,

    i'm trying to get variable in memory:
    guide here:
    Printing an address of a variable in C

    So i can get name of the string. and not address in memory

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > const char *setexplodetoname[]
    Well this has ZERO space allocated to it.

    > setexplodetoname[contents] = ch;
    So every time you do this, you're hosing someone else's memory.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Aug 2019
    Posts
    9
    Thanks it works

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. printf.c and C
    By jordanguyoflove in forum C Programming
    Replies: 13
    Last Post: 10-15-2008, 12:33 PM
  2. Help with printf
    By elliptic in forum C Programming
    Replies: 3
    Last Post: 09-13-2006, 11:03 PM
  3. about printf
    By cheesestick in forum C Programming
    Replies: 9
    Last Post: 03-25-2005, 01:32 PM
  4. make printf using printf?
    By germaneater in forum C Programming
    Replies: 9
    Last Post: 11-10-2004, 10:58 PM
  5. Bad printf()!
    By kirby1024 in forum C Programming
    Replies: 2
    Last Post: 06-02-2002, 09:24 AM

Tags for this Thread