Array for getting a word in C Language

I desperately need help right now, I'm stuck for days in C language where you need to type the words that will appear, its a memory game, i don't know how toput the words. then reccognize the words whether its correct or not. thank you guys very much in advance. something like this.

1
2
  array[10][]={"cat","dog","rat","fish","cow","sheep",[etc]};
  /*they will be automatic inputted then you must type them correctly to get points.*/
Last edited on
I think the fixed number you are putting is in the wrong place

shouldn't it be
 
char array[][10]={"cat","dog","rat","fish","cow","sheep",[etc]};


The first [] may be remain emptied because it can count by how many member in the array
but the second one shouldn't be because it's tells how long the maximum string size is.

I strange thought that you are stuck with this for days. If I am still very new just like you, I would probably hack and slash programming ( try everything and hope it works but don't really know why something works ).

I am hoping I am giving the correct answer because I never coded in C lang before just C++.
Last edited on
There is a problem in char names[][10] = {"Tyrannosaurus rex", "cat"};
We state that each row of table names has 10 characters, but attempt to initialize the first row with 18.

However, the OP apparently does not need mutable words.
const char* names[] = {"Tyrannosaurus rex", "cat"};
Now names is just a list of pointers, which point to const string literals.

The OP does need mutable character array(s) for the words that the user will give.
@keskiverto oh thanks for that, array is confusing. now i've got another problem. im stuck in the scanf, i cant get the proper formula for getting that.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<conio.h>
#include<string>

int main(){
	string typed;
	const char* array[] = { "Tyrannosaurus","cat" };

	for (int i = 0; i <= 2; i++){
		printf("%s \n", array[i]);
	}
	scanf("%c", &typed);
	if (typed = array[])
		{
			printf("%d Point!", s++);
		}
	_getch();
	return 0;
}
Last edited on
You cannot use C input functions wit C++ classes.
Either switch to stream operations or read info in char arrays.
Are you sure you are using C compiler ?
im using visual studio here, still dont know there is a c++ codes there
Topic archived. No new replies allowed.