Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

parameter `p' has just a forward declaration

Status
Not open for further replies.

blues77

Programmer
Jun 11, 2002
230
0
0
CA
i'm getting this error when i run this code. Any help is greatly appreciated!!!!


#include <stdio.h>
#include <stdlib.h>
#define NAME 10

typedef struct
{
char name[NAME];
int timeForExecution;
int timeLeft;
int waitTime;
int turnAroundTime;
} Process;


int main(int argc, char* argv[])
{
Process* p;
char name[NAME];
int numberOfProcesses = 0;
int timeSlice = 0;
int i = 0;
int execTime;

printf(&quot;Please enter the number of processes\n&quot;);
scanf(&quot;%d&quot;, &numberOfProcesses);
printf(&quot;Please enter the timeslice\n&quot;);
scanf(&quot;%d&quot;,&timeSlice);

//allocate memory
p = malloc(numberOfProcesses*sizeof(Process));

for(i = 0; i < numberOfProcesses; i++)
{
printf(&quot;Please enter a name for this process\n&quot;);
scanf(&quot;%s&quot;, name);
strcpy(p.name,name);

printf(&quot;Please enter the ammont of time this process requires to complete execution\n&quot;);
scanf(&quot;%d&quot;, &execTime);
p.timeForExecution = execTime;
}

roundRobin(p, numberOfProcesses, timeSlice);
}

roundRobin(Process* p; int numberOfProcesses, int timeSlice)
{
int i = 0;
for(i = 0; i < numberOfProcesses; i++)
{
printf(&quot;name = %s&quot;, p.name);
}
}
 
You are referencing a member variable by &quot;.&quot; operator. Its wrong. Use arrow opertor &quot;->&quot; in those places .

Corrected Code:

#include <stdio.h>
#include <stdlib.h>
#define NAME 10

typedef struct
{
char name[NAME];
int timeForExecution;
int timeLeft;
int waitTime;
int turnAroundTime;
} Process;


int main(int argc, char* argv[])
{
Process* p;
char name[NAME];
int numberOfProcesses = 0;
int timeSlice = 0;
int i = 0;
int execTime;

printf(&quot;Please enter the number of processes\n&quot;);
scanf(&quot;%d&quot;, &numberOfProcesses);
printf(&quot;Please enter the timeslice\n&quot;);
scanf(&quot;%d&quot;,&timeSlice);

//allocate memory
p = malloc(numberOfProcesses*sizeof(Process));

for(i = 0; i < numberOfProcesses; i++)
{
printf(&quot;Please enter a name for this process\n&quot;);
scanf(&quot;%s&quot;, name);
strcpy(p->name,name);

printf(&quot;Please enter the ammont of time this process requires to complete execution\n&quot;);
scanf(&quot;%d&quot;, &execTime);
p->timeForExecution = execTime;
}

roundRobin(p, numberOfProcesses, timeSlice);
}

roundRobin(Process* p, int numberOfProcesses, int timeSlice)
{
int i = 0;
for(i = 0; i < numberOfProcesses; i++)
{
printf(&quot;name = %s&quot;, p->name);
}
}

-Latha
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top