#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main()
{
int a = 0, len1 = 0, len2 = 0;
int BUFSIZE = 1000;
char *string1[1];
char *string2[1];
FILE *fp1 = fopen("input1.txt", "r");
FILE *fp2 = fopen("input2.txt", "r");
if ((fp1 == 0)||(fp2 == 0))
{
fprintf(stderr, "Error while opening");
return 0;
}
string1[a] = (char *)malloc(BUFSIZE);
string2[a] = (char *)malloc(BUFSIZE);
fgets(string1[0], BUFSIZE, fp1);
fgets(string2[0], BUFSIZE, fp2);
len1=strlen(string1[0]);
len2=strlen(string2[0]);
printf("%c\n", string1[0][4]);
printf("Output: \n");
srand(time(NULL));
printf("%s\n", string1[0]);
printf("%s\n", string2[0]);
printf("\n");
printf("%d %d", len1, len2);
printf("\n");
free(string1[0]);
free(string2[0]);
int x=0;
scanf("%d", &x);
fclose(fp1);
fclose(fp2);
return 0;
}
我需要从文件中读取一个字符串并将其存储在一个数组中。我只需要读取一行字符串,数组的每个元素都应该是字符串的一个字符。例如,如果我将“ABCDABC”读入一个数组,那么 array[3] 应该是“D”。但是我真的不知道怎么做,我修改了一些别人的代码,得到了上面的代码。但我不想在我的代码中涉及指针和地址的东西。那么谁能告诉我如何在不使用指针的情况下实现它?谢谢!