博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Creating one array of strings in c fails ,why?
阅读量:4679 次
发布时间:2019-06-09

本文共 441 字,大约阅读时间需要 1 分钟。

Error code:

#include<stdio.h>

#include<string.h>

#include<ctype.h>

#include<stdlib.h>

int main(void)

{

char *foo[100];//array of pointer

strcpy(f00[0],”测试");

printf(“%s”,foo[0]);

return 1;

}

问题:

分配了一个指针数组,如果需要分配各字符串给第一个指针,需要分配空间给特定的指针然后再赋值。

将foo[0]=malloc(13);//用完释放

strcpy(foo[0],”test file”);

例子二:

char foo[10][100]={0};

strcpy(foo[0],”test”);

strcpy_s(foo[0],100,”test”);

转载于:https://www.cnblogs.com/lxk613/archive/2011/12/30/2307645.html

你可能感兴趣的文章