I wrote some function to read input.txt and add the elements in this file to node, but it doesn't work anymore
would you mind check and figure out my mistake, thx alot
Code:
In function `input':
71 [Warning] assignment makes integer from pointer without a cast
75 subscripted value is neither array nor pointer
In function `main':
101 too few arguments to function `input'
Code:
Input.txt
6 2 4 3
-2 4 1 -3 7 6
Code:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
int rows, cols,row, col, k, i, element[10], p[10],array2;
int n,a,g,r;
int **rp, *ap;
typedef struct node *NodePtr;
struct node
{
int info;
NodePtr link;
};
void PrintContent(NodePtr pList)
{
NodePtr p=pList;
while (p!=NULL)
{ printf("%d ",p->info);
p=p->link;
}
printf("\n\n");
}
NodePtr CreateNode(int data)
{
NodePtr pA = (NodePtr) malloc(sizeof(struct node));
pA->info=data;
pA->link=NULL;
return pA;
}
void InsertNode(NodePtr *ppList, NodePtr newnode)// insert the newnode into the list pointed by *ppList.
{ if (*ppList==NULL)
// the list is empty
{
*ppList = newnode;
}
else if (newnode->info < (*ppList)->info)
// insert at the beginning of the list
{ newnode->link = *ppList;
*ppList = newnode;
}
else
{ NodePtr p=*ppList;
while (p->link!=NULL && p->link->info < newnode->info)
p = p->link;
// p will stop at the last node, or at the node
// after which we should insert the new node.
newnode->link = p->link;
p->link = newnode;
}
}
void input(FILE *file, char nameInput[]) //Function to read data from file
{
int j, i;
file = fopen(nameInput, "r");
if(file == NULL){
printf("Error:Can't open the file");
getch();
}
else{
printf("File opened successfully!\n");
}
fscanf (file,"%d",&n);
fscanf (file,"%d",&a);
fscanf (file,"%d",&g);
fscanf (file,"%d",&r);
array2 = malloc(n *sizeof(int));
for (j = 0; j < n; j++){
if(!feof(file))
{
fscanf(file,"%d",&array2[j]);
}
}
fclose(file);
}
void output(void)
{
int a[100];
FILE *fpoutput;
fpoutput=fopen("Output.txt","w");
for (i=0;i<3;i++)
fprintf(fpoutput,"%d ",a[i]);
fclose(fpoutput);
}
int main(void)
{
input();
output();
getch();
}