質問編集履歴

3

修正

2017/11/11 12:46

投稿

kakakaaka
kakakaaka

スコア17

test CHANGED
File without changes
test CHANGED
@@ -64,21 +64,21 @@
64
64
 
65
65
  for(int i=0; i<10; i++){
66
66
 
67
- printf("Input operation: push/pop : ");
67
+ printf("Input operation: push/pop:");
68
68
 
69
- scanf("%s", input);
69
+ scanf("%d", input);
70
70
 
71
71
  if(strcmp(input, p_push) == 0){
72
72
 
73
73
  printf("Input data : ");
74
74
 
75
- scanf("%s", &su);
75
+ scanf("%d", &su);
76
76
 
77
77
  push(su);
78
78
 
79
79
  }else if(strcmp(input, p_pop) == 0){
80
80
 
81
- printf("poped data : %d\n",pop(su));
81
+ printf("poped data : %d\n",push(su));
82
82
 
83
83
  }else{
84
84
 

2

修正

2017/11/11 12:46

投稿

kakakaaka
kakakaaka

スコア17

test CHANGED
File without changes
test CHANGED
@@ -52,13 +52,13 @@
52
52
 
53
53
  int main(){
54
54
 
55
- char *push = "push";
55
+ char *p_push = "push";
56
56
 
57
- char *pop = "pop"
57
+ char *p_pop = "pop";
58
58
 
59
59
  char input[10];
60
60
 
61
- int su=0;
61
+ int su;
62
62
 
63
63
 
64
64
 
@@ -68,9 +68,7 @@
68
68
 
69
69
  scanf("%s", input);
70
70
 
71
- if(strcmp(input, push) == 0){
71
+ if(strcmp(input, p_push) == 0){
72
-
73
- printf("push\n");
74
72
 
75
73
  printf("Input data : ");
76
74
 
@@ -78,13 +76,9 @@
78
76
 
79
77
  push(su);
80
78
 
81
- }else if(strcmp(input, pop) == 0){
79
+ }else if(strcmp(input, p_pop) == 0){
82
80
 
83
- printf("pop\n");
81
+ printf("poped data : %d\n",pop(su));
84
-
85
- scanf("%s", &su);
86
-
87
- pop(su);
88
82
 
89
83
  }else{
90
84
 
@@ -100,56 +94,4 @@
100
94
 
101
95
 
102
96
 
103
- main.c: In function 'main':
104
-
105
- main.c:29:3: error: expected ',' or ';' before 'char'
106
-
107
- char input[10];
108
-
109
- ^~~~
110
-
111
- main.c:34:19: error: 'input' undeclared (first use in this function); did you mean 'int'?
112
-
113
- scanf("%s", input);
114
-
115
- ^~~~~
116
-
117
- int
118
-
119
- main.c:34:19: note: each undeclared identifier is reported only once for each function it appears in
120
-
121
- main.c:39:6: error: called object 'push' is not a function or function pointer
122
-
123
- push(su);
124
-
125
- ^~~~
126
-
127
- main.c:27:9: note: declared here
128
-
129
- char *push = "push";
130
-
131
- ^~~~
132
-
133
- main.c:43:6: error: called object 'pop' is not a function or function pointer
134
-
135
- pop(su);
136
-
137
- ^~~
138
-
139
- main.c:28:9: note: declared here
140
-
141
- char *pop = "pop"
142
-
143
- ^~~
144
-
145
-
146
-
147
- exit status 1
148
-
149
-
150
-
151
-
152
-
153
-
154
-
155
97
  ```

1

修正

2017/11/11 12:11

投稿

kakakaaka
kakakaaka

スコア17

test CHANGED
File without changes
test CHANGED
@@ -1,24 +1,8 @@
1
- スタックで
2
-
3
- Input operation: push/pop : push
4
-
5
- Input data :3
6
-
7
- Input operation: push/pop : pop
8
-
9
- poped data :3
10
-
11
- このようにpushのときpopの時で作業が変わるようにしたいのですがpushと打ち込んでpushとpopを区別できるようにするにはどうすればよいのでしょうか?
12
-
13
- どうか教えてください。
14
-
15
-
16
-
17
-
18
-
19
1
  ```ここに言語を入力
20
2
 
21
3
  #include <stdio.h>
4
+
5
+ #include <string.h>
22
6
 
23
7
  #define MAX 100
24
8
 
@@ -68,33 +52,39 @@
68
52
 
69
53
  int main(){
70
54
 
71
- char a;
55
+ char *push = "push";
72
56
 
73
- int b;
57
+ char *pop = "pop"
74
58
 
75
- int i;
59
+ char input[10];
76
60
 
61
+ int su=0;
62
+
63
+
64
+
77
- for(i=0; i<10; i++){
65
+ for(int i=0; i<10; i++){
78
66
 
79
67
  printf("Input operation: push/pop : ");
80
68
 
81
- scanf("%s", &a);
69
+ scanf("%s", input);
82
70
 
83
- if(a = push){
71
+ if(strcmp(input, push) == 0){
72
+
73
+ printf("push\n");
84
74
 
85
75
  printf("Input data : ");
86
76
 
87
- scanf("%s", &b);
77
+ scanf("%s", &su);
88
78
 
89
- push(b);
79
+ push(su);
90
80
 
91
- }else if(a = pop){
81
+ }else if(strcmp(input, pop) == 0){
92
82
 
93
- printf("poped data : ");
83
+ printf("pop\n");
94
84
 
95
- scanf("%s", &b);
85
+ scanf("%s", &su);
96
86
 
97
- pop(b);
87
+ pop(su);
98
88
 
99
89
  }else{
100
90
 
@@ -108,4 +98,58 @@
108
98
 
109
99
  }
110
100
 
101
+
102
+
103
+ main.c: In function 'main':
104
+
105
+ main.c:29:3: error: expected ',' or ';' before 'char'
106
+
107
+ char input[10];
108
+
109
+ ^~~~
110
+
111
+ main.c:34:19: error: 'input' undeclared (first use in this function); did you mean 'int'?
112
+
113
+ scanf("%s", input);
114
+
115
+ ^~~~~
116
+
117
+ int
118
+
119
+ main.c:34:19: note: each undeclared identifier is reported only once for each function it appears in
120
+
121
+ main.c:39:6: error: called object 'push' is not a function or function pointer
122
+
123
+ push(su);
124
+
125
+ ^~~~
126
+
127
+ main.c:27:9: note: declared here
128
+
129
+ char *push = "push";
130
+
131
+ ^~~~
132
+
133
+ main.c:43:6: error: called object 'pop' is not a function or function pointer
134
+
135
+ pop(su);
136
+
137
+ ^~~
138
+
139
+ main.c:28:9: note: declared here
140
+
141
+ char *pop = "pop"
142
+
143
+ ^~~
144
+
145
+
146
+
147
+ exit status 1
148
+
149
+
150
+
151
+
152
+
153
+
154
+
111
155
  ```