scanf(“%d”,&a)
scanf(“%lf”,&a)
scanf(“%c”,&a)
scanf(“%u”,&a)
第1题:
请编写一个函数void fun(cbara [], charb [], int n),其功能是:删除一个字符申中指定下标的字符。其中,a指向原字符串,删除后的字符串存放在b所指的数组中,n中存放指定的下标。
例如,输入一个字符串world,然后输入3,则调用该函数后的结果为word。
注意:部分源程序给出如下。
请勿改动主函数main 和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <stdio.h>
include <conio.h>
define LEN 20
void fun (char a[], char b [], int n)
{
}
main ()
{
char str1 [LEN], str2 [LEN];
int n ;
clrscr ();
printf ("Enter the string : \n") ;
gets (str1) ;
printf ("Enter the position of the string
deleted: ");
scanf ("%d", &n) ;
fun (str1, str2, n) ;
printf ("The new string is : %s \n",
str2) ;
}
第2题:
请补充main函数,该函数的功能是:从键盘输入一个字符串及一个指定字符,然后把这个字符及其后面的所有字符全部删除。结果仍然保存在原串中。 例如,输入“abcdefg”,指定字符为“d”,则输出“abe”。 注意:部分源程序给出如下。 请勿改动main函数和其他函数中的任何内容,仅在main函数的横线上填入所编写的若干表达式或语句。 试题程序: include<stdlib.h> include<stdio.h> define M 80 void main { int i=0; char str[M]; char ch; system("CLS"); printf("\n Input a strin9:\n"); gets(str); printf("\n Input a charator;\n"); scanf("%c",&ch); while(str[i]!=\0) { if(str[i]==ch) 【1】 【2】 ; } str[i]=【3】 ; printf("\n***display string***\n"); puts(str); }
【1】break;【2】i++【3】\0
【解析】题目要求删除指定字符后的所有字符,将字符串中的字符从第一个开始与指定字符相比较,直到找到第一个与指定字符相同的字符结束。因此,【1】处填“break;”;【2】处填“i++”;为新的字符串添加结束符,因此,【3】处填“\O”。
第3题:
有以下结构体说明、变量定义和赋值语句
struct STD
{ char name[10];
int age;
char sex;
} s[5],*ps;
ps=&s[0];
则以下 scanf 函数调用语句中错误引用结构体变量成员的是
A)scanf("%s",s[0].name);
B)scanf("%d",&s[0].age);
C)scanf("%c",&(ps->sex));
D)scanf("%d",ps->age);
第4题:
请补充函数fun(),该函数的功能是;删除字符数组中小于等于指定字符的字符,指定字符从键盘输入,结果仍保存
例如,输入“abcdefghij”,指定字符为‘d’,则结果输出“defghij”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include <stdio. h>
define N 80
void fun (char s[], char ch)
{
int i=0, j=0;
while (s [i] )
{
if (s Iii<ch)
【 】;
else
{
【 】
i++;
}
}
【 】
}
main ()
{
char str [N], ch;
clrscr ();
printf("\n Input a string:\n");
gets (str);
printf("\n*** original string ***\n");
puts (str);
printf("\n Input a character:\n");
scanf ("%c", &ch);
fun(str, ch);
printf("\n*** new string ***\n");
puts (str);
}
第5题:
C语言中,getchar()函数与scanf()函数的区别在于getchar()只能用于字符的输入,而scanf()可以输入任意类型的数据。
此题为判断题(对,错)。
第6题:
编写一个函数,该函数可以统计一个长度为2的字符串在另一个字符串中出现的次数。例如,假定输入的字符串为asd asasdfg asd as zx67 asd mklo,子字符串为as,则应当输出6。
注意:部分源程序给出如下。
请勿改动主函数main和具他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <conio.h>
include <stdio.h>
include <string.h>
int fun(char *str, char *substr)
{
}
main ( )
{
char str[81],substr[3];
int n;
clrscr ();
printf ("输入主字符串 ");
gets (str);
printf ("输入子字符串");
gets (substr);
puts (str);
puts (substr);
n=fun (shr, substr);
printf("n=%d\n ",n);
}
第7题:
当用户要求输入的字符串中含有空格时,应使用的输入函数是( )。
A.scanf()
B.getchar()
C.gets()
D.getc()
第8题:
当用户要求输入的字符串中含有空格时,应使用的输入函数是
A)scanf()
B)getchar()
C)gets()
D)getc()
第9题:
当用户要求输入的字符串中含有空格时,应使用的输入函数是( )。
A.scanf
B.getchar
C.gets
D.getc
第10题:
输入二个 64 位的十进制数,计算相乘之后的乘积
已知 strcpy 函数的原型是:
char * strcpy(char * strDest,const char * strSrc);
1.不调用库函数,实现strcpy 函数。
2.解释为什么要返回char *。