簡體   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