-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPointerProblem.c
More file actions
64 lines (59 loc) · 1.38 KB
/
PointerProblem.c
File metadata and controls
64 lines (59 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <stdio.h>
#include <string.h>
#define MAX 3
#define WORDSIZE 31
int EnterWords(char words[][WORDSIZE],int nrOfWords);
void view(char words[][WORDSIZE],int nrOfWords);
int main(){
char menu;
char words[MAX][WORDSIZE];
int nrOfWords = 0;
do{
printf("a) lagga till, b) skriva ut, c) ta bort, d) avsluta: ");
scanf(" %c", &menu);
switch(menu){
case 'a':
nrOfWords = EnterWords(words,nrOfWords);
break;
case 'b':
view(words,nrOfWords);
break;
case 'c':
nrOfWords = 0;
break;
case 'd':
printf("avsluta");
break;
default:printf("Felaktigt val\n");
break;
}
}
while(menu != 'd');
return 0;
}
int EnterWords(char words[][WORDSIZE],int nrOfWords){
char check[WORDSIZE];
for(int i = nrOfWords; i < MAX; i++)
{
printf("ange ord (q for avslut):");
scanf("%s", check);
if(strcmp(check,"q")==0)
{
break;
}
else
{
strcpy(words[i], check);
nrOfWords++;
}
}
return nrOfWords;
}
void view(char words[][WORDSIZE],int nrOfWords)
{
for(int i = 0; i < nrOfWords; i++)
{
printf("%s, ",words[i]);
}
printf("\n");
}