Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Problem with pointers and string array. C. (http://www.go4expert.com/forums/pointers-string-array-c-t9428/)

Cheer 18Mar2008 13:57

Problem with pointers and string array. C.
 
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);

}


asadullah.ansari 18Mar2008 15:11

Re: Problem with pointers and string array. C.
 
search on google yaar!!! that's very silly things. Any p[lace you can get. Try if any doubt then ask.

Cheer 18Mar2008 15:44

Re: Problem with pointers and string array. C.
 
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;
}


madhukaraphatak 19Mar2008 12:17

Re: Problem with pointers and string array. C.
 
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:


All times are GMT +5.5. The time now is 11:49.