0
[C] Help with input of something like A2B3C6XD7E9X, use of strings and arrays is forbidden
The programme asks to input "string" of mixed letters and numbers like this: A2B3C6XD7E9X (where X means "missed attempt", the player is playing a game). Now, since I am not allowed to use strings or arrays, I thought of: 1) asking for input until a terminating character is found with do-while 2) since the player has exactly 9 attempts, stop input after 9 pairs 3) write something like scanf(" %c%d%c%d....",&a1,b1,a2,b2....); ,but realised I don't know what to do with X in such case Any suggestions on this?
7 Antworten
+ 1
you can just loop 9x for each attempt and if the char is not 'X'
then scan the integer coordinate.
for (int i=0; i<9; i++){
scanf("%c", &coord);
if (coord == 'X'){
printf("missed attempt\n");
}
else {
scanf("%d", &coordInt);
printf("%c%d\n", coord, coordInt);
}
}
+ 1
Something like:
while ((c = getchar()) != EOF) if (c != 'X') n = getchar();
+ 1
your question seemed vague and ambiguous
you said the player has exactly 9 attempts.
assuming an attempt is a coordinate of a
char and a decimal ex. A2
and X a missed attempt,
firstly, is the X counted as an attempt or not?
and
A2B3C6XD7E9X
has 7 attempts instead of 9
if X were to be counted as an attempt.
i feel like you mean you are not allowed to use strings because you will need to convert these coordinates into int later to be used on the 2d array, without knowing how to convert these coordinates into int in the first place.
please explain your questions with more detail.
0
Can you rephrase the Description cause I don't understand this game the player is playing, nor what the mixture of letters and numbers mean.
0
A2B3C6XD7E9X
means he picked A2 then B3 then C6 then skipped the move then picked D7 then E9 then skipped (where A2 are coordinates of a field on a board, it goes A1,A2,A3,... etc)
0
A2B3C6XD7E9X was just given as an example, yes it needs 2 more.
And X counts as an attempt too.
I am not allowed to use arrays or strings because the exercise is apparently meant to focus on simpler methods.