Thread: pointer array

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    32

    pointer array

    [code]
    #include<stdio.h>
    #include<conio.h>
    void main()

    {
    char *month[6]={"INVALID","JAN","FEB","MAR","MAY","JUNE"};
    printf("\n\t%c",*month[0]);
    getch();
    }
    [/pointer array code] .
    the above code prints: I
    how can i get the output any character within a string like V
    Last edited by samirself; 01-10-2005 at 10:49 AM.

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by samirself
    how can i get the output any character within a string like V
    ???
    Code:
    #include <stdio.h>
    
    int main ( void )
    {
       char *month[6] = { "INVALID", "JAN", "FEB", "MAR", "MAY", "JUNE"};
       int i, j;
       for ( i = 0; i < 6; ++i )
       {
          printf ( "month[%d] = \"%s\"\n", i, month [ i ] );
          for ( j = 0; month [ i ] [ j ]; ++j )
          {
             printf ( "month[%d][%d] = '%c'\n", i, j, month [ i ] [ j ] );
          }
       }
       return 0;
    }
    
    /* my output
    month[0] = "INVALID"
    month[0][0] = 'I'
    month[0][1] = 'N'
    month[0][2] = 'V'
    month[0][3] = 'A'
    month[0][4] = 'L'
    month[0][5] = 'I'
    month[0][6] = 'D'
    month[1] = "JAN"
    month[1][0] = 'J'
    month[1][1] = 'A'
    month[1][2] = 'N'
    month[2] = "FEB"
    month[2][0] = 'F'
    month[2][1] = 'E'
    month[2][2] = 'B'
    month[3] = "MAR"
    month[3][0] = 'M'
    month[3][1] = 'A'
    month[3][2] = 'R'
    month[4] = "MAY"
    month[4][0] = 'M'
    month[4][1] = 'A'
    month[4][2] = 'Y'
    month[5] = "JUNE"
    month[5][0] = 'J'
    month[5][1] = 'U'
    month[5][2] = 'N'
    month[5][3] = 'E'
    */
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    >> how can i get the output any character within a string like V

    month[0][2]

    and use code tags please.

    [edit]
    beat me to it
    [/edit]
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981

  5. #5
    Registered User xxxrugby's Avatar
    Join Date
    Jan 2005
    Posts
    178
    This is if I get right that you wanna see explicid char in string!
    This is how you can make that happen!


    I hope that this code will help you, and is something near what you looking for!

    Code:
    #include <stdio.h>
    
    int main ( void )
    {
       char *month[6] = { "INVALID", "JAN", "FEB", "MAR", "MAY", "JUNE"};
       int i, j, k = 0; char c;
       for ( i = 0; i < 6; ++i )
       {
          printf ( "month[%d] = ..%s..n", i, month [ i ] );
          for ( j = 0; month [i][j]; ++j )
          {
             printf ( "month[%d][%d] = '%c'\n", i, j, month[i][j] );
          }
       }
    
       printf("\nIn what string you want char?:");
       scanf("%d", &i);
    
       j = 0;
       while(month[ i ][ j ] != '\0') { k++; j++; }
    
       printf("\nYour string has =.. %d .. char\n", k);
       printf("\nOn what place you wanna see char ?= ");
       scanf("%d", &j);
    
       printf("\n%c\n", month[i][j - 1]);
    
       printf("\nIn ..%s.. for what char you wanna search ?= ", month[i]);
       scanf(" %c", &c);
       j = 0;
       while(month[i][j] != '\0')
       {
            if( month[i][j] == c)
            {
                printf("\n char ..%c.. found in month[%d][%d]", c, i, j);
            }
            j++;
       }
       printf("\n");
       system("PAUSE");
       return 0;
    }
    ---------------------------
    Sorry for spelling errors, not English.

    Rugby Is Life!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 05-29-2009, 05:48 AM
  2. sorting the matrix question..
    By transgalactic2 in forum C Programming
    Replies: 47
    Last Post: 12-22-2008, 03:17 PM
  3. pointer to array of structs
    By Luken8r in forum C Programming
    Replies: 2
    Last Post: 01-08-2008, 02:05 PM
  4. towers of hanoi problem
    By aik_21 in forum C Programming
    Replies: 1
    Last Post: 10-02-2004, 01:34 PM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM