Novice C language learning journey(10)

in Programming4 years ago

梦幻光晕蓝色背景矢量图.png
Take a sting constant "efgh" declare as character pointer type.take the value of "efgh" pass to anther "a" string constant.The "a" string constant is declared as character pointer type too.
But it did not shows the output of "efgh" on console.Because the "a" pointer has not point to the "c" array first address after executed the "for" statement.
The code as follows"

   #include"stdio.h"
   #include"stdlib.h"
   main(){
   char *a="abcd";
   char *b="efgh";
   char c[10];
   int i=0;
   for(;*b!='\0';b++,a++,i++){
          c[i]=*b;
          a=&c[i];  
   }
   printf("%s\n",a);
   system("pause");
   }

1.PNG

So how to modify?
The modified as follows:

  #include"stdio.h"
  #include"stdlib.h"
  main(){
  char *a="abcd";
  char *b="efgh";
  char c[10];
  int i=0;
  for(;*b!='\0';b++,a++,i++){
         c[i]=*b;
  }
  c[i]='\0';
  a=c;
  printf("%s\n",a);
  system("pause");
  }

2.PNG

Sort:  

Thank you for continuing to share your journey on the Programming Community. Upvoted!

According to the Bible, The Book of Judas: Should You Believe It?

Watch the Video below to know the Answer...

(Sorry for sending this comment. We are not looking for our self profit, our intentions is to preach the words of God in any means possible.)


Comment what you understand of our Youtube Video to receive our full votes. We have 30,000 #SteemPower. It's our little way to Thank you, our beloved friend.
Check our Discord Chat
Join our Official Community: https://steemit.com/created/hive-182074