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

Problem with pointers and string array. C.

Discussion in 'C' started by Cheer, Mar 18, 2008.

  1. Cheer

    Cheer New Member

    Joined:
    Mar 18, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Hello, could anyone help me with C language a little. I'm trying to write a program with pointers, which would scan some words to the array of strings and would print them on a screen. I'm new to C programming, that's why it's so difficult to deal with such a simple task :goofy:

    Code:
    #include <stdio.h>
    #include <string.h>
    
    int main () {
    
      char *  string[3];
      int i;
    
     ..............
     
      return (0);
    
    } 
     
  2. asadullah.ansari

    asadullah.ansari TechCake

    Joined:
    Jan 9, 2008
    Messages:
    356
    Likes Received:
    14
    Trophy Points:
    0
    Occupation:
    Developer
    Location:
    NOIDA
    search on google yaar!!! that's very silly things. Any p[lace you can get. Try if any doubt then ask.
     
  3. Cheer

    Cheer New Member

    Joined:
    Mar 18, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    i was trying to.. but I can't write a right code.. :worried: I can't find mistakes here..
    I'm new to C that's why this is difficult for me :undecided
    Code:
    #include <stdio.h>
    #include <string.h>
    
    int main ()
    {
    	char* string[3];
    	int j;
    	for(j=0;j<3;j++)
    	{
    	
    	fgets(string[j], sizeof string[j], stdin);
    		
    	}
    
    	for(j=0;j<3;j++)
    	{
    		printf("String number %d: \"%s\"\n", j, string[j]);
    	}
    	return 0;
    }
    
     
  4. madhukaraphatak

    madhukaraphatak New Member

    Joined:
    Dec 9, 2007
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    IT CAN BE BE DONE VERY EASILY
    CODE:
    Code:
              #include<stdio.h>
               #include<conio.h>
                void  main( )
                   {
                     
                      char *s[3];
                         int i;
                    
                       for(i=0;i<3;i++)
                          {
                             gets(s[i]);
                          }
                    for(i=0;i<3;i++)
                      {
                        printf("\n %d string is ",i);
                         printf("%s",s[i]);
                      }
    } 
    :charming:
     
    Last edited by a moderator: Mar 20, 2008

Share This Page