导航

补充作业

Posted on 2017-03-31 09:09  于金池  阅读(109)  评论(0编辑  收藏  举报
#include<stdio.h>//定义头文件
int main()//主函数
 {
    void funstr(char p[]);
    char str[]="hello world";//输入字符串并且赋初值
   
   printf("%s\n",str);//格式输出字符串
   str[0]='H';
   str[6]='W';
   funstr(str);
 }
    void funstr(char p[])//定义funstr函数
 {
     int i=0;//定义整型变量并且赋初值0
    
 while (p[i]!='\0')//用while语句输出整个字符串,到0字符停止
  {
      
      printf("%c",p[i++]);//输出字符串中的各个元素
  
  }
 printf("\n");
 printf("%s",p);//格式输出整个字符串
  
} 

hello world
Hello World
Hello World
--------------------------------
Process exited after 0.01692 seconds with return value 0
请按任意键继续. . .

 

【总结】:刚开始不知道怎么将字符串中的字母变成大写,后来知道了可以直接将字符串中的某个元素变成大写,还有调用funstr函数时,结构有些纰漏,在主函数中没有引用funstr函数,导致调用的funstr函数没有起到任何作用,还有%s是格式化输出整个字符串,以%s输出的形式的时候后面不需要写p[i]等字符,能直接输出整个字符串p,还有一些符号方面的小瑕疵.

              课上的时候我没有正确的调用函数,还有改变大小写上面的疑虑,以及各种小毛病没有及时改正,课下我询问了别人,并且经过多次编译改正,明白了很多问题,最后终于找到了错误,程序编译运行正确.

         

#include<stdio.h>
int main()
{
   struct STD
 {
    int num;
    char *name;
    int score;  
 };
  struct STD student1;
  
  student1.num=01;
  student1.name="ÓÚ½ð³Ø";
  student1.score=50;
  student1.score+=10;
  
  printf("%d,%s,%d",student1.num,student1.name,student1.score);
 
 
 } 

1,于金池,60
--------------------------------
Process exited after 0.02288 seconds with return value 0
请按任意键继续. . .