C语言。变化的确保和指针的排列。请求高手们。

来源:百度知道 编辑:UC知道 时间:2024/06/25 17:34:07
拜托帮看一下此题。由于是从日语翻译过来的,有些意思可能不太好理解。
实在急求帮助。希望好心人可以告诉我答案。我在这里向您表达衷心的谢意。

以程序的条件为标准,做一个程序。有一部分已经做好了。望参考
#include <stdio.h>
#include <stdlib.h>
#define NUM_STRING 10 //文字列的最大个数
#define MAX_LEN 1000 //文字配列的大小(入力文字列の最大长度+1)
int main( void )
{
int i;
int n; //文字列的个数
char data[MAX_LEN]={}; //入力用文字列
char *str_p[NUM_STRING]; //容纳文字列的指针排列
FILE *fp;
//1~3的処理

//文件的OPEN

//写入文件
fprintf(fp, "%d\n",n);
for(i=n-1;i>=0;i--)
fprintf(fp, "%s\n", str_p[i]);
//文件的CLOSE

return 0;
}
程序的条件:
1.从键盘输入英数字(最长为MAX_LEN(1000)-1个),容纳在文字列(文字排列)data后,显示。
2.变动的确保输入的文字列容纳在它一样长的文字列里的领域,然后把文字列data复制在那个领域里。要注意,必要的文字排列的长度是文字列的长+1字节。
(参考int strcmp(const char *s1, const char *s2)
char *strcpy(char *s1, const char *s2)
size_t strlen(const char *s)
3.输入文字列end,使入力后的文字列变为NUM_STRING(10)个为止,都要重复1

#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>
#include <string.h>
#define NUM_STRING 10
#define MAX_LEN 1000
int main( void )
{
int i;
int n;
char data[MAX_LEN];
char *str_p[NUM_STRING];
FILE *fp;
//1~3的処理
//1.从键盘输入任意英数字,存储在data后,显示。
i=0;
/

ar c;
printf("input strings:\n");
n=0;
scanf("%s",data);
str_p[n]=(char*)malloc(sizeof(char)*(strlen(data)+1));
strcpy(str_p[n],data);
while(strcmp(str_p[n],"end")!=0)
{
/* while((c=getchar())!='\n')
{
data[i]=c;
i++;
}
data[i]='\0';*/
printf("input strings:\n");
scanf("%s",data);
n++;
str_p[n]=(char*)malloc(sizeof(char)*(strlen(data)+1));
// temp[i]=0;
strcpy(str_p[n],data);

// str_p[k]=temp;
// if(temp=