Thread: Array & Strings Problem

  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    108

    Array & Strings Problem

    hey there,
    i need help on the following program.
    I need a full explanation on what this code prints please

    Code:
    #include <stdio.h>
    #include <string.h>
    
    
    void f1(struct St1 *Ptr1);
    void f2(struct St1 Ptr1);
    
    
    struct St1
    {
        char arr[15];
        char *ptr;
    };
    
    
    int main()
    {
        static char string[5][10] = {"Today","exam","is","very","fun"};
        struct St1 st1Arr[3] = {{"Good", *string}, {"Luck", *(string+1)}, {"!!", &string[1][2]}};
        struct St1* pSt1 = st1Arr;
        
        printf("%s\n", (*pSt1++).arr);
        printf("%s\n", (*++pSt1).ptr);  
    }
    thanks in advance

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Counter proposal:

    You run it, and tell us

    1) What the output is

    and

    2) What output you expected.

    Put a little bit more time into it, and save us time explaining things you already know, or don't care about.

  3. #3
    Registered User
    Join Date
    Jan 2013
    Posts
    108
    the output is:
    good
    am
    and trust me if i did understand or didn't put time in it like you said i probably wouldn't ask for help and i do care on knowing how to analyze it since i have an exam on it
    thanks again

  4. #4
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    Which part/line don't you understand?

    The first word "good" should be easy, isn't it?

    Bye, Andreas

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with array of strings !!
    By prashant8809 in forum C Programming
    Replies: 1
    Last Post: 09-04-2012, 04:26 AM
  2. An array of strings problem
    By ineedmunchies in forum C Programming
    Replies: 15
    Last Post: 12-14-2009, 07:48 PM
  3. problem with array of strings
    By cole in forum C++ Programming
    Replies: 11
    Last Post: 09-28-2008, 11:45 PM
  4. array of strings problem
    By dayknight in forum C Programming
    Replies: 3
    Last Post: 11-08-2005, 10:41 AM
  5. problem with array of strings
    By m00se123 in forum C++ Programming
    Replies: 1
    Last Post: 05-24-2002, 12:11 AM