Problem with pointers and string array. C.

Newbie Member
18Mar2008,13:57   #1
Cheer's Avatar
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);

}
TechCake
18Mar2008,15:11   #2
asadullah.ansari's Avatar
search on google yaar!!! that's very silly things. Any p[lace you can get. Try if any doubt then ask.
Newbie Member
18Mar2008,15:44   #3
Cheer's Avatar
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;
}
Newbie Member
19Mar2008,12:17   #4
madhukaraphatak's Avatar
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