Hi i am in a trouble please help me. in my program i had an array

int Maxwordcount[127];
int index=0;
char ltr;
char *typedword;


char word[127][300][30] = { 
{............................................................},  //  index = 0
{........................................................}  // index = 1
............
...................
............................
{"a", "and", "apple","adobe","anvira","avast"},   // index = 65
{"boat", "bat","ball","banner","base","back",bar","boot"},    //index=66
{"cat","coat","can","count","car","cad",.................. }, // index= 67
{"did","do","dad","dog",............................................},
.........
............    
...............
{"its","is","ill",........................................................},
........
............
.................
.....................
{"zoo","zib","zoophyte","zebra",.............................} // index = 90
...........
..............
..............


};


// Accept a word from user
printf("Enter the word");
gets(typedword);

ltr = *typeword;  //  pointer to the word

means
when user press 'apple' , the first letter is a , ie ltr = a . // first letter of the typed word

ascii value of a = 65.
So i want to point wordcount[65][300][30];

and if the typed word is there print the word from the that position from the array ,
and if the word is not found print " not found " .

and if the user typed again " apple " keep the count in Maxwordcount array

please help me ......

Before anything else you need to understand the basics.

char *typedword;
/ Accept a word from user
printf("Enter the word");
gets(typedword);

That doesn't work at many levels. char *typedword; can only hold the address of a char. It can't hold the value of a char. gets(typedword); is not an option. First, typedword is not pointing to a valid buffer where a string can live. Second, gets() is not a safe function to use, since it doesn't have a way of limiting the amount of input it can read from the user. If the buffer doesn't have appropriated space to hold everything the user enters, it will over flow and over write memory that should not be touched by it. fgets() is the function you can use.

example:

/* make a buffer to hold the user input */
char buffer[255];    /* it can hold a string of size 254 + '\0' */

/* declare a pointer to buffer */
char *typedword;   /* is not pointing to the right place yet */

/* initialize the pointer */
typedword = buffer;   /* pointing to a nice buffer of memory */

/* now ask the user for some input */
printf("Enter the word: ");
fflush(stdout);

/* read the input */
fgets(buffer, sizeof(buffer), stdin);

/* or you can use the pointer to read 
fgets(typedword, sizeof(buffer), stdin); */

i got the point . thanks. but i just thinks point to the first letter of user typed word . and access the array .

and my job is to solve the problem with simple basics of c. because now i completed the basics only in my syllabus.
So please....


Ok come on to the whole program .please.....

The user types "apple" into typedword .
You then set int pos = typedword[0] .
You also set int wordcount = 0; .

The loop to scan the array is

while ( wordcount < 300 && word[pos][wordcount][0] != '\0' ) {
  // something here
  wordcount++;
}

plz specify the idea to solve my whole problem . please.....

That was pretty much it, without giving you the whole program, and that just isn't going to happen.

Make some effort, then we'll help.

plz give the idea , please ....

please.. give some hints ...... its an assignment ...so please.... i am in trouble

plz give the idea , please ....

please.. give some hints ...... its an assignment ...so please.... i am in trouble

What part of Salem's BIG hint do you not understand?

The user types "apple" into typedword .
You then set int pos = typedword[0] .
You also set int wordcount = 0; .

The loop to scan the array is

while ( wordcount < 300 && word[pos][wordcount][0] != '\0' ) {
  // something here
  wordcount++;
}

Practically, the algorithm for your whole program is laid out there for you.

> please.. give some hints ...... its an assignment ...so please.... i am in trouble
Did you do all your other assignments by yourself?
Or did you try (and succeed) in getting someone else to do them?

If not, then helping you now simply delays the inevitable, which is you flunking off the course. So just take the hit and realise that programming is not for you and leave the course. Everyone who remains will benefit from the extra attention from the tutor.

If you were awake when strcmp() was explained, then you have everything you need and it's up to you to put it all together.
Trust me, this is easy. It's going to get a lot harder.

Guys guys... this ain't a homework solving forum... come on... are you stuck with some coding part?, then we will help you, gladly... but don;t expect us to do your homework... the algorithm you need to solve your problem is given by Salem... so please... put in some effort...

oh, i did not read salem post carefully , now i got all solutions , and my program is worked as perfect . thanks to everyone . and one more step i want to do is

my array is something like this

data[15][25][30] = { 
                       {"Apple","A","and"}
                   };

1) i am accepting input from user , if it is present in array // do something , print " found" etc...

if it is not in the array , how to store it into that array .

2) If user types "acer" , suppose it is not in the array ,then store the string to array ,

and when user types again " acer" store its count as 2 (occurrence of the string "acer" in the array ) . how to do it.

3) suppose i have an array maxcount[15];
when user enters a string starting with "a"

then store maxcount[0] = 0; // how to do it......
then increments ....
how to do it

Well if you really followed what I wrote, then you should have an index to the first free slot to copy a string to.

i don't understand , u got my doubt ,

suppose if user types

"a bat and a ball and"

if my array is

data[10][20][30] = { {"a","and","apple"},
                               {"bat","ball"}
                             };

from the sentence how i can count

count of "a" in sentence (users input) = 2;
count of "bat" in sentence (users input) = 1;
count of "and" in sentence (users input) = 2;
count of "ball" in sentence (users input) = 1;

and using these counts , how i can i print the sentence in screen from the array . please...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.