小编Tom*_*Tom的帖子

无法创建一个会反转字符串的程序

我正在使用Linux.我试图在c中编写一个程序,它将向后打印一个字符串.这是我的代码:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main (){
    char string[100];
    printf ("Enter string:\n");
    gets (string);
    int length = strlen (string)-1;
    for (length = length; length>=0; length--){
        puts (string[length]);
    }
}
Run Code Online (Sandbox Code Playgroud)

这是错误:

a.c:10: warning: passing argument 1 of ‘puts’ makes pointer from integer without a cast
/usr/include/stdio.h:668: note: expected ‘const char *’ but argument is of type ‘char’
/tmp/cc5rpeG7.o: In function `main':
a.c:(.text+0x29): warning: the `gets' function is dangerous and should not be used.
Run Code Online (Sandbox Code Playgroud)

我该怎么办?

c linux string invert

2
推荐指数
1
解决办法
386
查看次数

标签 统计

c ×1

invert ×1

linux ×1

string ×1