我怎么会让一个数组来存储字符串? [英] How would I make an array to store strings?
本文介绍了我怎么会让一个数组来存储字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我想用一个简单的程序来算出这个:
So I'm trying to figure this out with a simple program:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char a[]="lalala";
char b[]="bababa";
char c[]="nanana";
char d[3][10];
d[0][20]=*a;
d[1][20]=*b;
d[2][20]=*c;
printf("%s -- %s -- %s", d[0], d[1], d[2]);
return 0;
}
每当我运行它,这是什么出来:
Whenever I run it, this is what comes out:
( -- ╡■ :A&w═l&wÉ∟@ -- l&wÉ∟@
我想要做的就是让它打印出来
LALALA
BABABA
nanana
What I'm trying to do is make it print out lalala bababa nanana
我失去了一些东西明显或做我需要做更复杂的东西,使字符串数组?
Am I missing something obvious or do I need to do something more complicated to make an array for strings?
推荐答案
尝试使用的strcpy,而不是通过取消引用分配他们。
Try using strcpy instead of assigning them by dereferencing.
这篇关于我怎么会让一个数组来存储字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文