LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 12-06-2004, 05:02 AM   #1
davidtsl
LQ Newbie
 
Registered: Dec 2004
Posts: 3

Rep: Reputation: 0
Cannot compile c


Help!!!

Got problem compile and run this code. need it to search for domain/user and convert to user.domain in a log files.

#include "stdio.h"

int main(int argc, char *argv[])
{
FILE *fp,*fn;
char store[128];
int letter, update, spointer, i, rev, bpointer;
fp = fopen ( argv[1], "r" ) ;

if ( fp == NULL ){
printf ( "Cannot open source file" ) ;
exit();
}
else{
fclose(fp);
fp = fopen ( argv[1], "a" );
fputc(32, fp);
fclose(fp);
}
fp = fopen ( argv[1], "r" ) ;
//fseek(fp, 0, SEEK_SET);

fn = fopen ( "temp", "w" ) ;

if ( fn == NULL ){
printf ( "cannot open temp file " ) ;
fclose ( fn );
exit();
}
spointer = 0; // For tracking Array
bpointer = 0; // For tracking \ in Array
rev = 0;
while((letter=fgetc(fp)) != EOF)
{
if (letter == 32){
if (spointer == 0){
fputc( 32, fn);
spointer = 0;
}
else if (rev == 1) {
for (i=bpointer+1; i< spointer; i++){
update = store[i];
//putchar(store[i]);
//putchar(92);
fputc( update, fn);
}
update = 46;
fputc( update, fn);
for (i=0; i< bpointer; i++){
update = store[i];
fputc( update, fn);
}
update = 32;
fputc( update, fn);
rev=0;
bpointer=0;
spointer = 0;
}
else{
for(i=0;i < spointer; i++){
update = store[i];
fputc( update, fn);
}
update = 32;
fputc( update, fn);
spointer = 0;

}

}
else if (letter == 92){
rev = 1;
bpointer = spointer;
store[spointer] = letter;
spointer++;
}
else {
store[spointer] = letter;
spointer++;
}

/*
if (letter == 92)
{
fgetpos(fp, fpos);

//fpointer = fseek(fp,
update = 46;
fputc( update, fn);
}
else
{
fputc( letter, fn);
}
*/
}
//putchar(92);
fclose(fp);
fclose(fn);
fp = fopen ( argv[1], "w" ) ;
fn = fopen ( "temp", "r" );
while((letter=fgetc(fn)) != EOF)
{
fputc( letter, fp);
}
fclose(fp);
fclose(fn);
printf("Modification of file completed");
}
 
Old 12-06-2004, 05:07 AM   #2
LauroMoura
Member
 
Registered: Feb 2004
Location: Carpina, PE, Brazil
Distribution: Ubuntu 5.10
Posts: 44

Rep: Reputation: 15
Post the error messages and other info.....
 
Old 12-06-2004, 07:34 AM   #3
vharishankar
Senior Member
 
Registered: Dec 2003
Posts: 3,142
Blog Entries: 4

Rep: Reputation: 120Reputation: 120
And use the CODE tag to print the output of a program or a program listing. It makes it easier to read.
 
Old 12-06-2004, 10:22 PM   #4
davidtsl
LQ Newbie
 
Registered: Dec 2004
Posts: 3

Original Poster
Rep: Reputation: 0
Sorry I new in linux,

Had done the compiling in Windows and it working fine but once i try compiling it in linux, it just does not work. does linux support array in the first place.
 
Old 12-06-2004, 10:30 PM   #5
csfalcon
Member
 
Registered: Jun 2004
Location: MD
Distribution: Fedora Core
Posts: 269

Rep: Reputation: 31
This is C, the C language supports array therefore in Linux or any other OS array is supported.
 
Old 12-06-2004, 11:43 PM   #6
ritme909
Member
 
Registered: Nov 2004
Location: Washington DC
Distribution: Debian, LFS, FC2
Posts: 43

Rep: Reputation: 15
Well first of all 'exit()' should take an integer as a parameter, non-zero on failure. So void exit(int status), use man, it is your friend. 'man 3 exit'
 
Old 12-12-2004, 07:26 PM   #7
davidtsl
LQ Newbie
 
Registered: Dec 2004
Posts: 3

Original Poster
Rep: Reputation: 0
Edit the exit issue,

But i still get the Segmentation Fault when compile the code.
 
Old 12-12-2004, 08:36 PM   #8
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,950
Blog Entries: 11

Rep: Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860
If the COMPILATION fails with a segfault there's
a pretty good chance that you got some faulty RAM or
an amd chipset with timer settings that don't quite
match the quality of the RAM chips in use :)

The fact that it works well in windows just shows
that linux makes better use of the resources than
windows ...


Cheers,
Tink
 
Old 12-13-2004, 01:36 AM   #9
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,459

Rep: Reputation: 352Reputation: 352Reputation: 352Reputation: 352
davidtsl, can you decribe more precisely what is happening ?
Full error message ?
Is a core file generated ?
Are you able to compile other C programs ?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
compile 2.6.13 jupiter3437 Linux - Software 3 09-09-2005 04:09 PM
ntop compile/post-compile problem? tjb Linux - Software 3 12-28-2004 04:22 PM
Compile help Twiggy794 Linux - Software 1 12-03-2003 01:53 AM
How do I compile? icecream33 Programming 2 10-07-2002 06:28 AM
why won't the following compile? purpleburple Programming 4 09-10-2002 07:12 PM


All times are GMT -5. The time now is 11:29 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration