喵-见缝插针 2018-11-11 13:37 采纳率: 0%
浏览 218

如何使用字符、数组和指针在 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条回答 默认 最新

  • Lotus@ 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);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?