DIGIT-ARC read-only archive · snapshot: July 23, 2026

Small error in C implementing fCfS algo

8 posts · originally from https://geek.digit.in/community/threads/small-error-in-c-implementing-fcfs-algo.154831/

dharmil007
dharmil007 Original post #1
Mar 29, 2012 at 4:32 PM
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;
}
utkarsh73
Mar 30, 2012 at 9:10 PM
scanf ("%d", art);
scanf ("%d", jt[j]);


In both these scanf, seems like you have forgotten "&" symbol. like:
scanf("%d",&art);
scanf("%d",&jt[j]);
nbaztec
nbaztec #5
Mar 30, 2012 at 10:08 PM
^This
P
May 9, 2012 at 2:21 AM
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.
nims11
nims11 #7
May 9, 2012 at 2:42 AM
^^ What are you saying!
art is a pointer, not art, art is in fact *(atr+i).
nbaztec
nbaztec #8
May 9, 2012 at 11:46 AM
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.