zhayujie / C-Primer-Plus

C Primer Plus 6th edition exercises answers.

Home Page:https://zhayujie.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

chapter 6.7 exists warning

sukai-cheng opened this issue · comments

Warning:Implicit conversion loses integer precision: 'unsigned long' to 'int'

image

Pls check my code,thanks for your time~
AC:

#include <stdio.h>
#include <string.h>
#define WORD_SIZE 26
int main (void)
{
    char word[WORD_SIZE];
    printf("Input a word:\n");
    scanf("%s",word);
    for( long i = strlen(word);i >= 0; i--){
        printf("%c",word[i]);
    }
    printf("\n");
    return 0;
}

会有类型强转的warning,你的写法更规范,已修改,多谢指正。
PS: 以前的代码比较粗糙,仅供参考哈 ^_^