これが私のコードです:
#include <stdio.h>
#include <string.h>
void ignoreRestOfLine(FILE* fp)
{
int c;
while ( (c = fgetc(fp)) != EOF && c != '\n');
}
int main( void )
{
int num_times, count =0;
int length;
scanf("%d ", &num_times);
char s[100];
for(count=0 ;count<num_times;count++){
if ( fgets(s, sizeof(s), stdin) == NULL )
{
// Deal with error.
}
if ( scanf("%d", &length) != 1 )
{
// Deal with error.
}
ignoreRestOfLine(stdin);
size_t n = strlen( s );
size_t m = 5;
int i,j;
for ( i = 0; i < strlen(s)+1; i++ ){
putchar( '[' );
for ( j = 0; j < m; j++ )
{
char c = s[(i + j) % ( n + 1 )];
if ( !c )
c = ' ';
putchar( c );
}
printf( "]\n" );
}
}
}
最初の行は、入力したい符号の数を示しています。2 行目は、記号を出力する文字列を入力する場所です。3 行目は、マーキー内のスペースの数です。例えば:
Input:
1
Hello World!
5
Output:
[Hello]
[ello ]
[llo W]
[lo Wo]
[o Wor]
[ Worl]
[World]
[orld!]
[rld! ]
[ld! ]
[d! H]
[! He]
[Hel ]
[ Hell]
しかし、これは私のコードが実際に行うことです:
Input:
1
Hello World!
5
Output:
[Hello]
[ello ]
[llo W]
[lo Wo]
[o Wor]
[ Worl]
[World]
[orld!]
[rld!
]
[ld!
]
[d!
H]
[!
He]
[
Hel]
[ Hell]
この単純なエラーを修正するにはどうすればよいですか?