c语言模拟题1(有答案)
C语言程序设计 复杂程序考核
考核方法
考生在自己根目录下创建一个名为exam2.c的文件,在此文件中实现规定功能的函数。该文件中不包含main函数。调试时,学生自行编写相应的main函数等来进行测试。
函数功能
截取字符串将大写字母转换为小写字母
将被操作字符串中的指定大写字母后的所有字母截取出来,将截取出来的所有字母转换为小写字母,将此字符串写入原来被操作字符串的地址中。
比如:字符串”WEIWENDATA” 在字符’N’之后的的字符串为” DATA”;转换后的字符串”data”。
函数原型
int trans(char *str, char ch);
参数说明
str 为被操作的字符串首地址,字符串的元素全为大写字母;最终将转换好的字符串写入此地址中。
ch 为指定的大写字母,此大写字母在str中只出现一次;
返回值
操作成功,正常返回;
str为空,即str==NULL
#include
int trans(char *str, char ch){
int i = 0;
int j = 0;
if(str == NULL){
return 1;
}
while(*(str + i) != '\0'){
if(*(str + i) == ch){
break;
}
i++;
}
while(*(str + i + 1) != '\0'){
*(str + j) = *(str + i + 1) + 32;
j++;
i++;
}
*(str + j) = '\0';
}
void main()
{
char a[100] = "DHYOEBG";
char h = 'Y';
trans(a, h);
printf("%s", a);
}
C语言程序设计 复杂程序考核
考核方法
在名为exam2.c的文件中实现一个指定的函数,其要求如后所述。该文件中不应包含main函数。学生自行编写相应的main函数等来进行测试。源代码文件保存在学生账号的根目录下。
函数功能
删除链表中包含指定数据的节点。
该函数的功能为删除链表中指定数据的节点,链表的首节点地址以及所指定的数据以函数形式参数的形式传入。
函数原型
int delete_list(data * op_list, int value);
其中data数据类型定义如下:
//Link list struct
typedef struct data{
int value;
struct data *next;
}data;
结构体中的value成员为所存储的数据,next存储链表下一个节点的地址,如果不存在下一个节点,next值为NULL。
考生应当将上述的data定义的代码复制到源代码文件中。
参数说明
op_list为链表首节点的地址;
value 为指定的数据。考生需要找到结构体成员value值为指定数据的节点,并将之删除。
返回值
-1不存在指定数据;
0删除成功,正常返回。
#include
#include
typedef struct data{
int val;
struct data *next;
}data;
int delete_list(data * op_list, int dir){
struct data *head, *newP;
head = op_list;
if(head->next == NULL){
return 2;
}
while(head->next != NULL){
newP = head->next;
if(newP->val == dir){
head->next = newP->next;
}
head = head->next;
}
return 0;
}
struct data * creatList(){
int len = 0;
int id = 0;
int i = 0;
struct data * head = (struct data *)malloc(sizeof(struct data));
struct data * Tail = head;
printf("input len");
scanf("%d", &len);
for(i = 0; i < len; i++){
struct data * NewS = (struct data *)malloc(sizeof(struct data));
printf("input