繁体   English   中英

strcpy function 复制字符串

[英]strcpy function to copy string

我正在尝试使用strcpy将字符串从字符串数组复制到另一个字符串变量......这里有什么错误? 为什么 output 错了?

#include <stdio.h>
#include <string.h>

void main() {
    int i;
    char cw[3][12];
    for (i = 0; i < 3; i++)
        scanf("%s", &cw[i]);
    
    puts(cw[2]);
    char ch[12] = "hftiuh";
    puts(ch);
    strcpy(ch, cw[2]);
    puts(ch[12]);
}

输入

hello
again 
there

这给出了 output

there
hftiuh

预计 output

there
hftiuh
there

谢谢大家...只是查看我的愚蠢问题...特别是告诉它错误而不是告诉如何更正,它有帮助...我找到了答案,没有编译器错误只是为了清除大多数评论。 ..我变了

puts(ch[12]);

puts(ch);

感谢大家。

#include<stdio.h>
#include<string.h>
int  main()
{
    int i;
    char cw[3][12];
    for(i=0;i<3;i++)
        scanf("%s",*(cw+i));
    puts(cw[2]);
    char ch[12]="hftiuh";
    puts(ch);
    strcpy(ch,cw[2]);
    puts(ch);
    return 0;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM