三九宝宝网宝宝教育教学论文

c语言编程:倒序输出字符串:输入长度不超过100的字符串将其中

01月02日 编辑 39baobao.com

[C语言函数字符串截取分割]C标准库中提供了一个字符串分割函数strtok(); 实现代码如下: #include <stdio.h> #include <string.h> #define MAXSIZE 1024 int main(int argc, char * argv[]) { char dat...+阅读

代码供参考:

#include "stdio.h"

int main(void)

{

char InStr[100]; //保存输入字符串

char TmpStr[100]; //保存转换格式后的字符串

unsigned int i, j=0;

unsigned int style = 0; //格式类型 1: style_style_style 2: styleStyleStyle 3: error

//输入字符;

scanf("%s", InStr);

//先通过比较相邻的3个字符的ascii码来判断是哪种类型, 1: style_style_style 2: styleStyleStyle 3: error

for(i=0; i

{

//类型1: 第1个字符是小写,第2个字符是'_', 第3个字符是小写;

if((InStr[i]>96 & InStr[i]<123) & (InStr[i+1]=='_') & (InStr[i+2]>96 & InStr[i+2]<123))

{

style = 1;

break;

}

//类型2: 第1个字符是小写,第2个字符是大写, 第3个字符是小写;

else if((InStr[i]>96 & InStr[i]<123) & (InStr[i+1]>64 & InStr[i+1]<91) & (InStr[i+2]>96 & InStr[i+2]<123))

{

style = 2;

break;

}

//错误类型;

else

{

style = 3;

}

}

//开始转换并输出;

switch(style)

{

case 1:

for(i=0; i

{

if(InStr[i] != '_')

{

//去掉'_'后保存到另一数组;

TmpStr[j] = InStr[i];

j++;

}

}

printf("\n%s\n", TmpStr);

break;

case 2:

for(i=0; i

{

if(InStr[i]>64 & InStr[i]<91)

{

//将当前字符是大写的, 则ascii加上32变成小写;

InStr[i] = InStr[i] + 32;

}

//保存到另一数组;

TmpStr[j] = InStr[i];

j++;

}

printf("\n%s\n", TmpStr);

break;

case 3:

printf("\n error \n");

}

}

以下为关联文档:

C语言字符串使用strtok函数分割之后字符串在内存中位置是否有改变char buf[20] = "abc def mmmm"; char *p = strtok(buf," "); printf("buf=%s\n",buf); printf("p_addr=%p\n",p); printf("buf_addr=%p\n",buf); 输出:buf=abc,说明切割后buf中的第一个...

c语言倒序输出字符串1 2 3 4 5 6 7 8 9 10 11 12 #include<stdio.h> #include<string.h> intmain () { charstring[100]; inti; charc; gets(string); for(i=strlen(string);i--;)//<----------...

C语言字符串反转逆序输出已改,看注释 #include #include int main() { char a[31][31],*start,*end; int i=0,t,len,k=0; while(gets(a[i])!=NULL) { len=strlen(a[i]); start=a[i];end=&a[i][len-1]...

请教C语言字符串倒序输出#include<stdio.h> #include<string.h> void main() { char string1[200]; //用于存放输入的字符串 char string2[200]; //用于存放倒序后的字符串 int invertion(char *ch1,...

如何用C语言将字符串逆序输出C语言程序如下: #include<stdio.h> #include<string.h> main() { int i,j,t,n; char a[10]; printf("请输入2113字符串:"); gets(a); n=strlen(a); for(i=0;i<=n/2;i++) { t=a[i];...

C语言递归倒序输出字符串#include<stdio.h> void f() { char ch; if((ch = getchar())!='\n') f(); if(ch!='\n') printf("%c", ch); //这个输出语句是写在了递归调用之后,会被压栈,先压栈的后输出,所以可...

C语言怎么把带有空格的字符串倒序输出 # include "stdio.h" void out(char *s) { char *p; for(p=s; *p&*p!=' ';)p++; if(*p)out(++p); for(; *s&*s!=' ';)putchar(*s++); putchar(' '); } int main() { char s[2...

C程序字符串倒序输出你的函数没有返回值。 把a,b两个数组设为全局变量就好了。 就这样就行了: #include "stdio.h" char a[20],b[20]; char str(char a[],char b[]) { int m=19,n; for(n=0;m>-1;n+...

用C语言编程:常见字符串倒序输出的程序给个例子: #include<stdio.h> int main() {char s[100],*p; gets(s); for(p=s;*p;p++); for(;p>=s;p--) printf("%c",*p); printf("\n"); getch(); return 0; }...

推荐阅读
图文推荐