Small error in C implementing fCfS algo

dharmil007

Journeyman
Small error in C implementing fCfS algo

I m trying to implement fCfS Algo.
The programm is not ful fledged complete.
But the programm ends abruptly after the first input

So pls can anyone help me whats wrong ?

PHP:
#include <stdio.h>

int nopr,art[50],jt[50],start,wt[50],i,j,k,l,m;
void fcfs ()
{
	//int i,j,k,l,art[50],jt[50],start,wt[50];
	printf ("\n Enter arrival Time in ascending order\n");
	for (i=0;i<=nopr;i++)
	{
		scanf ("%d", art[i]);
	}
	printf ("\n Enter job Time\n");
	for (j=0;j<=nopr;j++)
	{
		scanf ("%d", jt[j]);
	}
	for (k=1;k<=nopr;k++)
	{
		start=art[i]+jt[j];
		wt[l]=start-art[i];
	}
	printf ("fCfS Algo");
	printf ("The waiting Time for each process is :\n");
	for (m=0;m<=nopr;m++)
	{
		printf ("%d",wt[l]);
	}

}
int main ()
{
	//int nopr,art[50],jt[50],start,wt[50],i,j,k,l;
	printf  ("\n\n------------- Scheduling Algorithm fCfS -------------\n\n");
	printf ("Enter no of process \n");
	scanf ("%d\n",&nopr);
	fcfs ();
	return 0;
}
 
Last edited by a moderator:
In both these scanf, seems like you have forgotten "&" symbol. like:
scanf("%d",&art);
scanf("%d",&jt[j]);


I do not think that is the problem because in C sub-scripted variables such as arrays, are by default, pointers. And the & operator in C is the "address of" operator, which returns the memory location of the variable(as a pointer). So in the scanf("%d", art) is completely valid. No need to explicitly give & symbol.
 

nbaztec

Master KOD3R
I do not think that is the problem because in C sub-scripted variables such as arrays, are by default, pointers. And the & operator in C is the "address of" operator, which returns the memory location of the variable(as a pointer). So in the scanf("%d", art) is completely valid. No need to explicitly give & symbol.


Incorrect.

PHP:
char *str1 = "Hello";
char str2[] = "Hello";
Here str1 is a pointer, str2 is a pointer but neither str1[0], nor str2[0] are pointers. They are char locations.

So, scanf("%s", str2) will work but scanf("%c", str2[0]) will not.
 
Top Bottom