33,317
社区成员
发帖
与我相关
我的任务
分享#include <strings.h>
#include <stdio.h>
int main(void)
{
char input[255];
char ch;
int i, length;
printf("Please enter a word: \n");
scanf("%c", &ch);
i = 0;
while (ch != '\n')
{
input[i] = ch;
scanf("%c", &ch);
i++;
}
length = strlen(input);
for (i = length-1; i >=0; i--) // 初始化语句 i -= 1 则正常;
printf("%c", input[i]);
printf("\n");
return 0;/***
*strlen.c - contains strlen() routine
*
* Copyright (c) Microsoft Corporation. All rights reserved.
*
*Purpose:
* strlen returns the length of a null-terminated string,
* not including the null byte itself.
*
*******************************************************************************/
#include <cruntime.h>
#include <string.h>
#pragma function(strlen)
/***
*strlen - return the length of a null-terminated string
*
*Purpose:
* Finds the length in bytes of the given string, not including
* the final null character.
*
*Entry:
* const char * str - string whose length is to be computed
*
*Exit:
* length of the string "str", exclusive of the final null byte
*
*Exceptions:
*
*******************************************************************************/
size_t __cdecl strlen (
const char * str
)
{
const char *eos = str;
while( *eos++ ) ;
return( eos - str - 1 );
}