三生石@ 2018-11-11 13:37 采纳率: 100%
浏览 233

如何使用字符、数组和指针在 c 中写这个函数? [电话暂停]

I have already tried it and i know it is a bit rude to ask but I am really new to c... please someone help

1.

void strcpy_upper(char *dest, const char *src); 

which copies string src into string dest converting all lowercase letters in a text string to uppercase.

2.

void strremdup(char* dest, const char* src); 

which copies the string src into string dest ignoring repeated adjacent characters.

3.

void swap_random(char* str); 

which swaps characters randomly in string src.

my attempt at the first one :

 void mystrcpy(char *dest, const char *src)
 {
      int i;
      for (i = 0; src[i] != '\0'; i++)
      {
           dest[i] = src[i];
      }
      dest[i] = '\0';
      printf("%c", *src);
 }

 int main()
 {
      char P[5] = "hell";
      char K[5];
      mystrcpy(P, K);
      system("pause");
      return 0;
 }

转载于:https://stackoverflow.com/questions/53249296/how-to-write-this-function-in-c-using-character-array-and-pointers

  • 写回答

1条回答 默认 最新

  • ~Onlooker 2018-11-11 15:42
    关注

    You're passing the parameters in wrong order, mystrcpy() should be called as:

    mystrcpy(K, P);
    

    since you're copying from K to P

    Also, to print string use %s

    printf("%s", dest);
    
    评论

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)