Problem with pointers and string array. C.

Cheer's Avatar, Join Date: Mar 2008
Newbie Member
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

Code:
#include <stdio.h>
#include <string.h>

int main () {

  char *  string[3];
  int i;

 ..............
 
  return (0);

}
0
asadullah.ansari's Avatar, Join Date: Jan 2008
TechCake
search on google yaar!!! that's very silly things. Any p[lace you can get. Try if any doubt then ask.
0
Cheer's Avatar, Join Date: Mar 2008
Newbie Member
i was trying to.. but I can't write a right code.. I can't find mistakes here..
I'm new to C that's why this is difficult for me
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;
}
0
madhukaraphatak's Avatar, Join Date: Dec 2007
Newbie Member
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]);
                  }
}

Last edited by shabbir; 20Mar2008 at 12:05.. Reason: Code block