You are here:

C/help plz

Advertisement


Question
hi
finally see you available
i have a problem in this programme below i want this programme to get several word and puts each character in for example sent[i][j](for instance gets the words bita&mitra and put them into sent[i][j] like this:sent[0][0]='b' sent[0][1]='i' sent[0][2]='t' sent[0][3]='a'
sent[1][0]='m' sent[1][1]='i' sent[1][2]='t' sent[1][3]='r' sent[1][4]='a' )so when i want the word whit for example the row number of '1' it gives me the word 'mitra'.







#include<stdio.h>
#include<string.h>
void main(){
   int i=0,j=0,d=0,w=0;
   char c=0,sent[10][10];
   for(i=0;i<=5;i++){
       for(w=0;w<=5;w++){
           while(c!=' '){
              c=getchar();
              sent[i][j]=c;
              j++;
           }
              sent[i][j]=0;
       }
       j=0;
   }
                      printf("/////////////////////////////\n");
              printf("%s\n",sent);
              printf("/////////////////////////////\n");
                      printf("Enter your number:\n");
                      d=getchar();
                      i=d;
              printf("%s\n",sent);
}


this is the programme that i should right i put all my attempts on it but it doesnt word i think the problem is in getting the words but dont know whats the problem and really want your help

Answer
Hai Dear Bita !

Thanks for your question , ive written a simple code ,hope it will meet all your conditions ,


#include<stdio.h>

void main()
{
  char name[10][30];
  int opt;
  /* Array can acomidate name 10 names of maximum of 30 characters */

  int i , j;
  char ch;

  for( i = 0 ; i < 10; i++)
  {
     for( j = 0 ; j < 30 ; j++)
     {
        ch = getchar();
           if( ch != ' ')
              name[i][j] = ch;
           else if ( ch == ' ')
              break;
     }
     name[i][j] = '\0';
  }

  printf("Enter a number from 0 to 9");
  scanf("%d" , &opt);
  printf("Name = %s" , name[opt]);
}

Note: I didn't test this code , i kindly request you to do the same , and revert me in case of issue to my email : princeatapi@yahoo.co.in

Thanks and Regards !

Prince M. Premnath

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Prince M. Premnath

Expertise


I'm sure that I can solve any doubts in Turbo C ,Graphics Programing ,Mouse, Hardware Programming ,File System ,Interrupts, BIOS handling , TSR Programming , General Concepts in C Language, handling inline Assembly statements

Experience

Research over 6+ Years

Organizations
CG-VAK Softwares and Exports Limited

Education/Credentials
Masters in Computer Applications

©2012 About.com, a part of The New York Times Company. All rights reserved.