teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

5

回答者の方の関数を参考にしてみました。

2019/02/20 15:09

投稿

shimchan
shimchan

スコア15

title CHANGED
File without changes
body CHANGED
@@ -9,19 +9,21 @@
9
9
  C言語
10
10
  ソースコード
11
11
  #include<stdio.h>
12
- #include <string.h>
12
+ #include<string.h>
13
+ #include<ctype.h>
13
14
 
14
- main(int argc,char *argv[]){
15
+ int main(int argc,char *argv[]){
15
16
  char *str = argv[1];
16
17
  int i;
17
18
  for(i = 0;i<strlen(str);i++){
18
- if(str[i]>='A'&&str[i]<='Z'){
19
+ if(islower(str[i])){
19
20
  str[i]--;
20
- }else if(str[i]>='a'&&str[i]<='z'){
21
+ }else if(isupper(str[i])){
21
22
  str[i]--;
22
23
  }
23
24
  }
24
25
  printf("%s\n",str);
26
+ return 0;
25
27
  }
26
28
 
27
29
  ```

4

訂正

2019/02/20 15:09

投稿

shimchan
shimchan

スコア15

title CHANGED
File without changes
body CHANGED
@@ -8,8 +8,8 @@
8
8
 
9
9
  C言語
10
10
  ソースコード
11
- /#include<stdio.h>
11
+ #include<stdio.h>
12
- /#include <string.h>
12
+ #include <string.h>
13
13
 
14
14
  main(int argc,char *argv[]){
15
15
  char *str = argv[1];
@@ -24,7 +24,7 @@
24
24
  printf("%s\n",str);
25
25
  }
26
26
 
27
-
27
+ ```
28
28
  ### 試したこと
29
29
 
30
30
  コマンドラインにて英単語を出力し、一文字ずつその文字が大文字か小文字かを判定し、前のアルファベットに変換させたりしていたのですが、途中でわからなくなり断念しました。

3

少し改良しました。

2019/02/20 14:56

投稿

shimchan
shimchan

スコア15

title CHANGED
File without changes
body CHANGED
@@ -14,7 +14,7 @@
14
14
  main(int argc,char *argv[]){
15
15
  char *str = argv[1];
16
16
  int i;
17
- for(i = 0;i<strlen[str];i++){
17
+ for(i = 0;i<strlen(str);i++){
18
18
  if(str[i]>='A'&&str[i]<='Z'){
19
19
  str[i]--;
20
20
  }else if(str[i]>='a'&&str[i]<='z'){

2

改めて書き直し

2019/02/20 14:47

投稿

shimchan
shimchan

スコア15

title CHANGED
File without changes
body CHANGED
@@ -8,8 +8,8 @@
8
8
 
9
9
  C言語
10
10
  ソースコード
11
- #include<stdio.h>
11
+ /#include<stdio.h>
12
- #include <string.h>
12
+ /#include <string.h>
13
13
 
14
14
  main(int argc,char *argv[]){
15
15
  char *str = argv[1];

1

ソースコードの追加

2019/02/20 14:46

投稿

shimchan
shimchan

スコア15

title CHANGED
File without changes
body CHANGED
@@ -8,8 +8,23 @@
8
8
 
9
9
  C言語
10
10
  ソースコード
11
- ```
11
+ #include<stdio.h>
12
+ #include <string.h>
12
13
 
14
+ main(int argc,char *argv[]){
15
+ char *str = argv[1];
16
+ int i;
17
+ for(i = 0;i<strlen[str];i++){
18
+ if(str[i]>='A'&&str[i]<='Z'){
19
+ str[i]--;
20
+ }else if(str[i]>='a'&&str[i]<='z'){
21
+ str[i]--;
22
+ }
23
+ }
24
+ printf("%s\n",str);
25
+ }
26
+
27
+
13
28
  ### 試したこと
14
29
 
15
30
  コマンドラインにて英単語を出力し、一文字ずつその文字が大文字か小文字かを判定し、前のアルファベットに変換させたりしていたのですが、途中でわからなくなり断念しました。