1.编写字符串查找函数mystrchr()。该函数的功能是在字符串中查找指字符,如果有该字符,则返回该字符在字符串中第一次出现的位置,则返回0,然后编写主函数进行验证。函数原形为: int mystrchr( char string[], char c);写出完整C程序; 2.编一程序,将字符串“He11o,C++!”赋给一个字符数组,然后从第一个字母开始间隔地输出该串(请用指针完成)。写出完整C程序。 3.1)建立职工数据结构,结构含有姓名、序号、性别和年龄信息; 2)建立一个结构数组,以便放置10个职工信息; 3)设计一个输入函数,输入职工的信息; 4)编写一个显示输出函数,用来输出结构数组的内容; 写出完整C程序。 结构数组

时间: 2023-04-04 17:02:23 浏览: 69
1. 以下是mystrchr函数的完整C程序: #include <stdio.h> int mystrchr(char string[], char c); int main() { char string[] = "Hello, world!"; char c = 'o'; int position = mystrchr(string, c); printf("The position of %c in %s is %d\n", c, string, position); return 0; } int mystrchr(char string[], char c) { int i; for (i = 0; string[i] != '\0'; i++) { if (string[i] == c) { return i + 1; } } return 0; } 2. 以下是用指针完成的程序: #include <stdio.h> int main() { char string[] = "Hello, C++!"; char *p = string; while (*p != '\0') { printf("%c", *p); p += 2; } printf("\n"); return 0; } 3. 以下是职工数据结构的程序: #include <stdio.h> struct Employee { char name[20]; int id; char gender; int age; }; void input(Employee employees[], int n); void output(Employee employees[], int n); int main() { Employee employees[10]; input(employees, 10); output(employees, 10); return 0; } void input(Employee employees[], int n) { int i; for (i = 0; i < n; i++) { printf("Enter information for employee %d:\n", i + 1); printf("Name: "); scanf("%s", employees[i].name); printf("ID: "); scanf("%d", &employees[i].id); printf("Gender (M/F): "); scanf(" %c", &employees[i].gender); printf("Age: "); scanf("%d", &employees[i].age); } } void output(Employee employees[], int n) { int i; printf("Employee information:\n"); for (i = 0; i < n; i++) { printf("Name: %s\n", employees[i].name); printf("ID: %d\n", employees[i].id); printf("Gender: %c\n", employees[i].gender); printf("Age: %d\n", employees[i].age); } } 注意:以上程序中的结构体为Employee,而非题目中的“职工”。

相关推荐

最新推荐

recommend-type

SQL SERVER2012中新增函数之字符串函数CONCAT详解

SQL Server 2012有一个新函数,就是CONCAT函数,连接字符串非它莫属。比如在它出现之前,连接字符串是使用"+"来连接,如遇上NULL,还得设置参数与配置,不然连接出来的结果将会是一个NULL。本文就介绍了关于SQL ...
recommend-type

python通过自定义isnumber函数判断字符串是否为数字的方法

主要介绍了python通过自定义isnumber函数判断字符串是否为数字的方法,涉及Python操作字符串判断的相关技巧,需要的朋友可以参考下
recommend-type

C语言中查找字符在字符串中出现的位置的方法

主要介绍了C语言中查找字符在字符串中出现的位置的方法,分别是strchr()函数和strrchr()函数的使用,需要的朋友可以参考下
recommend-type

MySQL 字符串截取相关函数小结

在工作中,可能需要将某些字段按某个分割符组成一个字符串作为字段值存取到数据库表中,比如某个任务对应三个结果,分别存储在不同的数据表中,这时可以将这三个不同表的主键按照约定的顺序进行组合(主键a:主键b:...
recommend-type

详解C++ string常用截取字符串方法

string常用截取字符串方法有很多,但是配合使用以下两种,基本都能满足要求: find(string strSub, npos); ...例1:直接查找字符串中是否具有某个字符串(返回”2″) std::string strPath = E:\\
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

list根据id查询pid 然后依次获取到所有的子节点数据

可以使用递归的方式来实现根据id查询pid并获取所有子节点数据。具体实现可以参考以下代码: ``` def get_children_nodes(nodes, parent_id): children = [] for node in nodes: if node['pid'] == parent_id: node['children'] = get_children_nodes(nodes, node['id']) children.append(node) return children # 测试数
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。