Jump to content


- - - - -

gcc c compile/execute question


3 replies to this topic

#1 Abyzmic

    Tequila Kitty!

  • Sponsors
  • 1706 posts
  • Location:Virginia, USA

Posted 21 November 2004 - 08:58 PM

I am having trouble figuring out how to execute a c program that i compiled on a linux machine at school. Is there a command I have to use to get it to compile or am i just doing the entire thing wrong? It compiles and runs under windows without a problem.

the file is serial.c
i compile it using gcc -o serial serial.c
no messages occur and i have a file called serial put into the dir

i've tried just typing it in as 'serial' with no luck. i've been googling with still no answer past the compile part.

#include <stdio.h>
#include <stdlib.h>

int main(int argc,char **argv)
{
	char buffer[64];
	char strFile[16] = "NodeData(0).dat";
	double *M;
	double *MV;
	double *V;
	FILE *fptr;
	int c=0,r=0;
	int iDim = 0;
	int iNumOfNode = 0;
	
	// Get the vector and matrix from the file
	if((fptr = fopen(strFile,"r")) == NULL)
	{
  printf("Error reading from data file %s.",strFile);
  exit(1);
	}

	// Get the dimension and number of nodes from the file
	iDim = atoi(fgets(buffer,64,fptr));
	iNumOfNode = atoi(fgets(buffer,64,fptr));

	// Allocate space for vectors and matrix
	M = malloc(iDim * iDim * sizeof(double));
	MV = malloc(iDim * sizeof(double));
	V = malloc(iDim * sizeof(double));

	// Read in vector information
	for(r=0;r<iDim;r++)
  V[r] = atof(fgets(buffer,64,fptr));
	
	// Read in matrix information
	for(c=0;c<(iDim*iDim);c++)
  M[c] = atof(fgets(buffer,64,fptr));

	// Close file
	fclose(fptr);

	// Calculate M*V using single processor
	for(r=0; r<iDim; r++)
	{
  MV[r] = 0;
  for(c=0; c<iDim; c++)
  	MV[r] = MV[r] + M[(r * iDim) + c] * V[c];
	}

	for(r=0; r<iDim; r++)
  printf("%lf\n",MV[r]);

	// Free memory reserved and set pointers to null
	free(M);
	free(MV);
	free(V);
	M = MV = V = NULL;
	
	return 0;
}


#2 Sudhakar

    n00b

  • Members
  • Pip
  • 11 posts
  • Location:India
  • Interests:Programming and web development.

Posted 21 November 2004 - 09:19 PM

I hope u are doing absolutly right. Ok after compilation u will get a binary file called "Serial" jst run that file on konsole as ./serial

I hope this will work and ur program will run

#3 Abyzmic

    Tequila Kitty!

  • Sponsors
  • 1706 posts
  • Location:Virginia, USA

Posted 22 November 2004 - 02:35 AM

ah, thank you, that worked perfectly. So why the ./serial and not just serial?

#4 Sudhakar

    n00b

  • Members
  • Pip
  • 11 posts
  • Location:India
  • Interests:Programming and web development.

Posted 22 November 2004 - 03:48 AM

U know when u compile programs with "gcc -o" option it will output as a binary executable file in the same directory. And for running an executable file we have to use "./" in linux.

I am happy that it helped u. You are most welcome. U know i was jst surfing on this site and seen ur question. to answer ur question only i have registered :D . But i think now this forum is really good i will be active :)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users