I've already posted this code in my former posts, but the issue here is different, I want to print the name that's given in the input.txt, also supposing I can't change the array's name size as its size stable as 4, but in the sscanf that's would make a serious problem, can anybody suggest me away to
solve the problem? thanks in advance, and once again,
supposing that I cant change the size of the array that's
inculded in the struct.
Code:
#include <string.h>
Code:
#include <stdio.h>
#include<stdlib.h>
typedef struct
{
char name[4];// the name of the document-in my case documt
}memIdentity;
memIdentity *Array[100]={0};
void Wikipedia_poll(char name[4], memIdentity *Array[100])
{
int i=0;
for(i=0; i<100; i++)
{
if (Array[i] == NULL)
{
Array[i]= (memIdentity*) malloc(sizeof(memIdentity));
strcpy(Array[i]->name,name);
printf("%s", Array[i]->name);
Array[i]->size = size;
break;
}
}
return;
}
void print_result()
{
int i=0;
for (i=0; i<100; i++)
{
if (Array[i]!=NULL)
printf("%s", Array[i]->name);
//here..the problem here is actually not printing the given name//
if (Array[i]==NULL)
printf("H");
}
}int main()
{
FILE *pToFile = fopen("C:/input.txt","r");
char line[30];
char name[4];
int j=0;
while( fgets( line, 30, pToFile ))
{
if (strstr(line, "Cboard OP'S") == line)
if (sscanf(line,"%*[^:]: %*s %4s %*s",name) =1)
Wikipedia_poll(name);
if (strstr(line, "print result") == line)
print_result();
}
fclose(pToFile);
return 0;
}