C语言编程 求指导 1.定义两个字符数组s1、s2,并用赋初值的方法把两个字符串”Compute

C语言编程 求指导
1.定义两个字符数组s1、s2,并用赋初值的方法把两个字符串”Computer”和”Language” 分别存放到s1、s2中,不用库函数strcat( ),把s2连接到s1的尾部,然后用%s格式输出连接后的字符串s1。
2.用赋初值的方法把字符串” C is a general purpose, procedural, imperative computer programming language developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system.” 存放到字符数组s中,编程统计其中的大写字母、小写字母、数字、空格、逗号的个数。
*3. 扩展:编写一个程序,将字符数组s2中的全部字符复制到字符数组s1中。不用strcpy函数。

 1.
#include <stdio.h>
#include <string.h>
#include <assert.h>
char* cat(char* des, char* src)
{
 char* p;
 assert(des != NULL);
 assert(src != NULL);
 p = des + strlen(des);
 while (*p++ = *src++);
 return des;
}
int main()
{
 char s1[100] = "Computer";
 char s2[100] = "Language";
 cat(s1, s2);
 printf("%s\n", s1);
 return 0;
}

2.

#include <stdio.h>
#include <ctype.h>
int main()
{
 char s[] = "C is a general purpose, procedural, imperative computer \
  programming language developed in 1972 by Dennis Ritchie at the \
  Bell Telephone Laboratories for use with the Unix operating system.";
 int up, low, num, space, dot;
 char* p = s;
 up = low = num = space = dot = 0;
 while (*p)
 {
  if (isupper(*p))
   up++;
  else if (islower(*p))
   low++;
  else if (isdigit(*p))
   num++;
  else if (' ' == *p)
   space++;
  else if (',' == *p)
   dot++;
  p++;
 }
 printf("大写字母: %d\n", up);
 printf("小写字母: %d\n", low);
 printf("数字: %d\n", num);
 printf("空格: %d\n", space);
 printf("逗号: %d\n", dot);
 return 0;


3.
#include <stdio.h>
#include <assert.h>

char* copy(char* des, char* src)
{
 char* p = des;
 assert(des != NULL);
 assert(src != NULL);
 while (*p++ = *src++);
 return des;
}

int main()
{
 char s1[100];
 char s2[] = "abcdefg";
 copy(s1, s2);
 printf("%s\n", s1);
 return 0;
}

追问

你编的我看不懂啊T^T

追答

第几个程序看不懂?哪一行看不懂你标出来,我给你解释

追问

指针我们没讲过

追答

好吧,我彻底无语了,等你什么时候看懂了再来采纳我的回答吧

温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-10-27
这几个题楼主就好好自己做吧。它们可是面试常见问题之一哦!
十个公司的面试题中就有九个公司喜欢出这种题目。
第2个回答  2019-02-24

第一题

#include<string>
#include<iostream>
using namespace std;
int main()
{
string s1="Computer",s2="Language";
cout<<s1+s2;
}

第3个回答  2013-10-30
楼主工程大的吧。。。。。
相似回答