下面程序的功能是将八进制正整数字符串转换为十进制整数。请填空。#include “stdio.h”#include “string.h”main(){ char *p,s[6];int n;p=s;gets(p);n= ① ;while( ② !=’\0’) n=n*8+*p-‘0’;printf(“%d\n”,n);}
查看答案
下面程序的功能是删除字符串s中的所有空格。请填空。#include “stdio.h”#include “string.h”#include “ctype.h”main(){ char c,s[80];int i=0;c=getchar();while(c!='\n') { s[i]=c; i++; c=getchar(); }s[i]=’\0‘;delspace(s);puts(s);}delspace( char *p){ int i,t;char c[80];for(i=0,t=0; ① ; i++)if( !isspace( ② )) c[t++]=p[i];c[t]=’\0’;strcpy(p,c);}
下面程序的功能是将字符串a的所有字符传送到字符串b中,要求每传送三个字符后再存放一个空格,例如字符串a的内容为”abcdefg”,则字符串b为”abc def g”,请填空。#include “string.h”main(){ char *p,a[80],b[80];int i,k=0; p=a;gets(p);while(*p){ for(i=0; ① ; p++,k++,i++) b[k]=*p;if( ② ) {b[k]=’ ‘; k++; } }b[k]=’\0’;puts(b);}
在C程序中,指针变量能够赋________________值或___________________值。
下面程序段是把从终端读入的一行字符作为字符串放在字符数组中,然后输出。请填空。int i; char s[80],*p;for(i=0;i<79;i++){ s[i]=getchar();if(s[i]==’\n’) break; }s[i]=__________________________________;p=____________________________________;while( *p) putchar(*p++);