# Small error in C implementing fCfS algo



## dharmil007 (Mar 29, 2012)

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 ?


```
#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;
}
```


----------



## krishnandu.sarkar (Mar 29, 2012)

Why 





> scanf ("%d\n",&nopr);



Simply use scanf ("%d",&nopr);


----------



## dharmil007 (Mar 29, 2012)

_


krishnandu.sarkar said:



			Why 

Simply use scanf ("%d",&nopr);
		
Click to expand...


_

Now it abruptly ends after entering first value in 





> Enter arrival Time in ascending order


.

As first value is entered it just ends abruptly


----------



## utkarsh73 (Mar 30, 2012)

> 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 (Mar 30, 2012)

^This


----------



## paul.soumyabrata (May 9, 2012)

utkarsh73 said:


> 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 (May 9, 2012)

^^ What are you saying!
*art* is a pointer, not *art*_, *art* is in fact **(atr+i)*._


----------



## nbaztec (May 9, 2012)

paul.soumyabrata said:


> 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._


----------

