c语言颠倒字符顺序

为什么80%的码农都做不了架构师?>>>   hot3.png

一个粗糙的实现:
#include

#define LEN 100

void reverse(char s[],int len_s);

main()
{
    char str[LEN];
    int length;
    while((length=my_getline(str,LEN))>0) {
        reverse(str,length);
    }
}
void reverse(char s[],int len_s)
{
    int i;
    for (i=len_s;i>=0;i--){
        putchar(s[i]);
    }
}


int my_getline(char s[], int lim)
{
	int c, i;

	for (i = 0; i < lim - 1 && (c = getchar()) != EOF && c != '\n';
	     ++i)
		s[i] = c;
	if (c == '\n') {
		s[i] = c;
		++i;
	}
	s[i] = '\0';
	return i;
}




转载于:https://my.oschina.net/sukai/blog/309314

你可能感兴趣的:(c语言颠倒字符顺序)