c
1#include <stdio.h> 2#include <string.h> 3 4int main(void) 5{ 6 char *s = "abcdef"; 7 //int c = 'L'; 8 int c; 9 char *ret; 10 printf("文字列:abcdef\n"); 11 printf("番号"); 12 scanf("%d", &c); 13 14 ret = strchr( s, c ); 15 if( ret != NULL ){ 16 printf( "%d番目の文字:%ld¥n", c, ret - s ); 17 } 18 else{ 19 printf( "%cはありません¥n", c ); 20 } 21 22 return 0; 23}
やりたいこと
1番目の文字:a
というようにscanf
で入力した番号の文字を出力したい。
やりたいこととprintfで出力している文章が全然違うのですが…。
すいませんでした。修正しました。
回答3件
あなたの回答
tips
プレビュー