Announcement: Be excellent to each other.


Caravel Forum : Other Boards : Anything : I survived (with your help)
1
Page 2 of 2
New Topic New Poll Post Reply
Poster Message
stigant
Level: Smitemaster
Avatar
Rank Points: 1182
Registered: 08-19-2004
IP: Logged
icon Re: SOS help with ANSI C before 28.II.2005 ! (+1)  
segfaults if parameter given doesn't match valid filename

you should be able to check the return value from fopen if the filename is invalid:

FILE *pFile;
pFile = fopen("ofiara.met", "r");

if ( pFile == NULL ) {
printf( "Hey, dummy, make sure you give me a real file\\n" );
}

My program can process only one file at a time

Are you taking a command line argument to indicate the file or are you reading it in after the program starts?

And puts data on stdin instead of files (i'm working on it right now, as it seems its most lacking feature).

you can actually fix that via the command line using the > operator:

myprogram > outputfile

should force all stdout data to go to outputfile instead of the screen.

____________________________
Progress Quest Progress
02-27-2005 at 08:19 PM
View Profile Send Private Message to User Show all user's posts Quote Reply
b0rsuk
Level: Smiter
Avatar
Rank Points: 489
Registered: 11-23-2003
IP: Logged
icon Re: SOS help with ANSI C before 28.II.2005 ! (0)  
stigant wrote:

you should be able to check the return value from fopen if the filename is invalid:

FILE *pFile;
pFile = fopen("ofiara.met", "r");

if ( pFile == NULL ) {
printf( "Hey, dummy, make sure you give me a real file\\n" );
}


Thanks ! It works. I used to use "argc != 1" before, this is even better.

My program can process only one file at a time

Are you taking a command line argument to indicate the file or are you reading it in after the program starts?


command line argument.
EDIT: to clarify:
I simply replaced "ofiara.met" with argv[1].
And added argv[] as second argument to main function, althrough it may be not necessary, it's supposed to work this way by default I think.
I don't think I can develop something nice in time, so I'm about to write bash script file with something like this:
./a.out gdansk-rebiechowo/EPGD-2004-04-20-15H.txt
./a.out gdansk-rebiechowo/EPGD-2004-04-20-18H.txt
....

Of course it's not exactly flexible, but it's going to work to a degree. And I can create it relatively fast with ls > script.sh

Still it's better than having it process only one file. I would get lower note for just sitting and crying.


you can actually fix that via the command line using the > operator:

myprogram > outputfile

should force all stdout data to go to outputfile instead of the screen.

It just won't work on windows, but my crude shell script wont, either.
EDIT: I'd prefer putting data from each line (visibility, weather etc) into separate file. But I'll use this solution if I won't be able to correct the program in time.

[Edited by b0rsuk at Local Time:02-27-2005 at 09:09 PM]

[Edited by b0rsuk at Local Time:02-27-2005 at 09:13 PM]

____________________________

http://www.gamasutra.com/features/20051128/adams_01.shtml
02-27-2005 at 09:06 PM
View Profile Send Private Message to User Send Email to User Show all user's posts Quote Reply
ErikH2000
Level: Legendary Smitemaster
Avatar
Rank Points: 2794
Registered: 02-04-2003
IP: Logged
icon Re: SOS help with ANSI C before 28.II.2005 ! (+1)  
b0rsuk wrote:
It just won't work on windows, but my crude shell script wont, either.
EDIT: I'd prefer putting data from each line (visibility, weather etc) into separate file. But I'll use this solution if I won't be able to correct the program in time.
You can call fopen("outfile.txt", "wb+") at the beginning. Then change all of your printf() calls to fprintf() passing the file handle returned from fopen(). At the end of your program call fclose() on the file handle.

Getting it into gnuplot format is harder, but maybe you still have enough time. You'd need to copy the values you're currently storing temporarily in word1, word2, word3 into separate variables for the information that will later be output to the gnuplot file, i.e. store temperature in an int variable called "temperature". Your strings in word1/word2/word3 can be converted to integers with calls to atoi() or atol(). After you are done parsing the meteo file, close it, and write your gnuplot file with fopen(), fprintf(), and fclose().

-Erik

____________________________
The Godkiller - Chapter 1 available now on Steam. It's a DROD-like puzzle adventure game.
dev journals | twitch stream | youtube archive (NSFW)
02-27-2005 at 09:31 PM
View Profile Send Email to User Show all user's posts This architect's holds Quote Reply
stigant
Level: Smitemaster
Avatar
Rank Points: 1182
Registered: 08-19-2004
IP: Logged
icon Re: SOS help with ANSI C before 28.II.2005 ! (0)  
I simply replaced "ofiara.met" with argv[1].
And added argv[] as second argument to main function, althrough it may be not necessary, it's supposed to work this way by default I think.
I don't think I can develop something nice in time, so I'm about to write bash script file with something like this:

ok, that's probably the best way anyway.... you can use the other argument to main to tell you how many files are specified. change your program to look like this:

/* can't remember if argc or argv comes first, however you have it now is probably correct */
void main( int argc, char * argv[] ) {
  int i;
  for ( i = 1; i < argc; i++ ) {
     /* insert current body of your program to process argv[i] */

   }
}


____________________________
Progress Quest Progress
02-27-2005 at 09:56 PM
View Profile Send Private Message to User Show all user's posts Quote Reply
b0rsuk
Level: Smiter
Avatar
Rank Points: 489
Registered: 11-23-2003
IP: Logged
icon Re: SOS help with ANSI C before 28.II.2005 ! (0)  
ErikH2000 wrote:
b0rsuk wrote:
It just won't work on windows, but my crude shell script wont, either.
EDIT: I'd prefer putting data from each line (visibility, weather etc) into separate file. But I'll use this solution if I won't be able to correct the program in time.
You can call fopen("outfile.txt", "wb+") at the beginning. Then change all of your printf() calls to fprintf() passing the file handle returned from fopen(). At the end of your program call fclose() on the file handle.

That's a bit confusing. But anyway, I'll settle for putting into same file via > . It's 22:55 here, I start work at 8:00 and end at 11:50. Not so much time left.
I just can't afford being sleepy in my work, not to mention coming late (3rd time - reduced salary).QC's are nice girls, but rules are rules. We don't want any ships going down ;]

Getting it into gnuplot format s harder, but maybe you still have enough time. You'd need to copy the values you're currently storing temporarily in word1, word2, word3 into separate variables for the information that will later be output to the gnuplot file, i.e. store temperature in an int variable called "temperature". Your strings in word1/word2/word3 can be converted to integers with calls to atoi() or atol(). After you are done parsing the meteo file, close it, and write your gnuplot file with fopen(), fprintf(), and fclose().
-Erik


Gnuplot documentation is much, much more obscure than C. I already wasted more than several hours trying to understand how to draw points with fixed coordinates (from file).

I don't see much point in storing in other variables for later. Temperature and most other things excluding weather (rare occurences) can be found in only one place in file.

So if I save them for later, or write immediately after scanning, each file will be opened once per program execution anyway.


I just got an idea about processing multiple files. For loop with something like this:
for(i = 0; i<=argc; i++)
fopen (argv, "r") {
Rest of program
}

Could it possibly work ?
I'll backup and try.

____________________________

http://www.gamasutra.com/features/20051128/adams_01.shtml
02-27-2005 at 10:14 PM
View Profile Send Private Message to User Send Email to User Show all user's posts Quote Reply
b0rsuk
Level: Smiter
Avatar
Rank Points: 489
Registered: 11-23-2003
IP: Logged
icon "Final" version (+1)  
#include <stdio.h>
#include <string.h>

/*clear sky*/
#define vis1 0
#define vis2 1
#define vis3 2
#define vis4 3
#define maxl 80

/*mist*/
#define wea1 0
/*fog*/
#define wea2 1
/*freezing fog*/
#define wea3 2
/*shallow fog*/
#define wea4 3
/*patches of fog*/
#define wea5 4
/* light rain, zeby sie odroznialo od zgrai mgiel */
#define wea6 8
/* chmurki, zeby sie odroznialo */
#define wea7 12
/* light rain showers, zeby sie odroznialo od zgrai mgiel */
#define wea8 9

int main(int argc, char *argv[])
{
    int ismiec;

    char line[80];
    char word1[20];
    char word2[20];
    char word3[20];

    FILE *pFile;

/* obsluga parametrow + komunikat */
    int i;
    for (i = 1; i < argc; i++) {
	pFile = fopen(argv[ i], "r");
	if (pFile == NULL)
	    printf("Argumenty musza byc poprawnymi nazwami plikow\\n");
	else
/* dla kazdego parametru (pliku) przetwazanie kazdej linii */
	    while (fgets(line, maxl, pFile) != NULL) {
		/* zczytywanie i przepisywanie wiatru */
		if (sscanf
		    (line, "Wind: from the %*s (%s degrees) at %s", word1,
		     word2) == 2) {
		    printf("%s \\n", word1);
		    printf("%s \\n", word2);

		}
		/* ...gdy wiatr zmienny */
		else if (sscanf(line, "Wind: Variable at %s", word1) == 1) {
		    printf("%s \\n", word1);
		}
		/* Widocznosc - wiecej niz... */
		else if (sscanf(line, "Visibility: greater than %s", word1)
			 == 1) {
		    printf("%s \\n", word1);
		    /* Widocznosc - mniej niz 1 */
		} else if (sscanf(line, "Visibility: less than %s", word1)
			   == 1) {
		    printf("%s \\n", word1);
		    /* widocznosc */
		} else if (sscanf(line, "Visibility: %s", word1) == 1) {
		    printf("%s \\n", word1);
		    /* niebo */
		} else
		    if ((sscanf
			 (line, "Sky conditions: %s %s", word1,
			  word2) == 2)
			||
			(sscanf
			 (line, "Sky conditions: %s %s", word1, word2)
			 == 1)) {
		    if (strcmp(word1, "clear") == 0)
			printf("%d \\n", vis1);
		    else if ((strcmp(word1, "mostly") == 0)
			     && (strcmp(word2, "clear") == 0))
			printf("%d \\n", vis2);
		    else if ((strcmp(word1, "partly") == 0)
			     && (strcmp(word2, "cloudy") == 0))
			printf("%d \\n", vis3);
		    else if ((strcmp(word1, "mostly") == 0)
			     && (strcmp(word2, "cloudy") == 0))
			printf("%d \\n", vis4);
		    else
			printf("Nieznane zachmurzenie");
		    /* pogoda */
		} else
		    if (sscanf
			(line, "Weather: %s %s %s", word1, word2, word3)
			>= 1) {
		    if (strncmp(line, "Weather: mist", 13) == 0) {
			if ((strcmp(word2, "shallow") == 0)
			    && (strcmp(word3, "fog") == 0)) {
			    printf("%d \\n", wea1);
			    printf("%d \\n", wea4);
			} else
			    printf("%d \\n", wea1);
		    }
		    if (strncmp(line, "Weather: fog", 12) == 0)
			printf("%d \\n", wea2);
		    if (strncmp(line, "Weather: freezing fog", 21) == 0)
			printf("%d \\n", wea3);
		    if (strncmp(line, "Weather: shallow fog", 20) == 0)
			printf("%d \\n", wea4);
		    if (strncmp(line, "Weather: patches of fog", 23) == 0)
			printf("%d \\n", wea5);
		    if (strncmp(line, "Weather: light rain", 19) == 0) {
			if (strcmp(word3, "showers") == 0)
			    printf("%d \\n", wea8);
			else if (strcmp(word3, "mist") == 0) {
			    printf("%d \\n", wea8);
			    printf("%d \\n", wea1);
			} else
			    printf("%d \\n", wea6);
		    }
		    if (strncmp
			(line, "Weather: Cumulonimbus clouds observed", 37)
			== 0)
			printf("%d \\n", wea7);
		    /* Temperatura w stopniach Fahrenheita, zeby bylo dokladniej */
		} else if (sscanf(line, "Temperature: %s", word1) == 1) {
		    printf("%s \\n", word1);
		    /* Windchill jakis... */
		} else if (sscanf(line, "Windchill: %s", word1) == 1) {
		    printf("%s \\n", word1);
		    /* Punkt rosy, cokolwiek by to bylo */
		} else if (sscanf(line, "Dew Point: %s", word1) == 1) {
		    printf("%s \\n", word1);
		    /* wilgotnosc */
		} else
		    if (sscanf(line, "Relative Humidity: %d%*s", &ismiec)
			== 1) {
		    printf("%d \\n", ismiec);
		    /* cisnienie */
		} else
		    if (sscanf(line, "Pressure %*s %*s %*s %*s (%s", word1)
			== 1) {
		    printf("%s \\n", word1);
		}
	    }
    }
    return 0;
}


So this is the version I am going to show at university, today. Yes, today because it's 00:26. Yaaawn.

It has all the bells and whistles I am capable of making, but prints everything on stdin. And doesn't care about time and date, so graph would probably be broken (no X coordinate).
Obviously the output format is nowhere close to Gnuplot input style. Except for it's all numbers, no words anymore. :=/

____________________________

http://www.gamasutra.com/features/20051128/adams_01.shtml
02-27-2005 at 11:33 PM
View Profile Send Private Message to User Send Email to User Show all user's posts Quote Reply
b0rsuk
Level: Smiter
Avatar
Rank Points: 489
Registered: 11-23-2003
IP: Logged
icon The Celebration is over (0)  
I couldn't get my hands on any printer recently.
Yesteday, when I was about to send it to my univ @mail, network went down.
When I came back from work today, it stopped working shortly after I turned on my computer.
I have no floppy disk drive, and never had.

So I went to the university only to find there's no way for me to have the program printed there. Unless I have it on fdd. I tried hard to access my webmail from text terminal (with both lynx and links), but in vain. The site was overloaded for most of the time, etc.
I tried to save it from drod.net forum, but I guess it wasn't right time to learn links/lynx details. 'p'rint didn't do me much good on laggy terminal.

Then I went to the person who was supposed to check my program. I talked with him, and he said I have time till Wednesday. And it has to be printed. He said something along the lines that the one at the top, you know, with big pointy teeth and power to rule them all, may be angry. And it all depends how good my program will be.

I hoped for more time to finish the program. So here it is, not exactly the way I expected it :(
For a good start I returned home and immediately fell asleep. I woke up about half an hour ago.
It's not over yet... %)
EDIT
How high is the limit for files opened simultaneously ? It seems that I'd need about 11 files opened at the same time. My Spellbook confused me with information that most systems put limits on number of files that can be opened at once. How high, approximately, can be the limit ?
I wanted 10 files opened as long as program works (output files), and 11th file is being opened and closed with each loop body.
EDIT
I added something like:

FILE *pWdi;
FILE *pWsp;
....
pWdi = fopen("1winddir.dat", "r");
pWsp = fopen("2windspd.dat", "r");

at start of main function. It runs fine, except for Segfault when I type in wrong kind of parameter. It used to work correctly.
The message printed for wrong pFile opened still works, but it's followed by Segmentation Fault.

I cannot copy and paste at this moment, unless you volounteer to recompile my kernel with usb2.0 support and new soundcard.
STATUS UPDATE:
My program now prints data into separate files.I still need it to print X coordinate (I have to somehow merge day and hour into one number, I believe), and other Gnuplot format tweaks remain.
It still segfaults when I give non-file parameters. No idea why, because it prints warning just like before and shouldn't go any further. Thats after I open data files for writing.

[Edited by b0rsuk at Local Time:02-28-2005 at 06:18 PM: Idiocy]

[Edited by b0rsuk at Local Time:02-28-2005 at 06:52 PM]

[Edited by b0rsuk at Local Time:02-28-2005 at 07:35 PM]

____________________________

http://www.gamasutra.com/features/20051128/adams_01.shtml
02-28-2005 at 05:47 PM
View Profile Send Private Message to User Send Email to User Show all user's posts Quote Reply
ErikH2000
Level: Legendary Smitemaster
Avatar
Rank Points: 2794
Registered: 02-04-2003
IP: Logged
icon Re: The Celebration is over (+1)  
b0rsuk wrote:
EDIT
b0rsuk, I would have replied to this earlier, but I don't get e-mail notification for edits. If you make new reply posts instead of editing, then I'll see it. And other people like stigant and Schik, too.
How high is the limit for files opened simultaneously ? It seems that I'd need about 11 files opened at the same time.
On some systems, it's a little less than 1024. You really shouldn't need to have 11 files open simultaneously though. Only the files you are actively working with should be open--1 or 2, in your case, I would think.
It runs fine, except for Segfault when I type in wrong kind of parameter. It used to work correctly.
The message printed for wrong pFile opened still works, but it's followed by Segmentation Fault.
Are you checking the handle returned from all your fopen() calls? If it is NULL, then show the error message but also make sure that no code uses that file handle next.

Another technique that is useful for debugging this: Add extra printf() calls in your code so you can see where execution is going. You want to know which statement in your code causes the segment fault. You can take these extra printf() messages out later. So say you have a call to fopen() with two messages printing out before and after like this:
  printf("I got this far!\\r\\n");
  FILE *pFile = fopen("somefile.txt", "r");
  printf("I got even farther!\\r\\n");

When you run your program, if it segment faults on fopen() you'll see only the first printf() message. If it segment faults after the fopen() then you'll see both messages. When I am troubleshooting like this, I usually just put in a bunch of numbers for messages, i.e. printf("1") printf("2").

-Erik

____________________________
The Godkiller - Chapter 1 available now on Steam. It's a DROD-like puzzle adventure game.
dev journals | twitch stream | youtube archive (NSFW)
03-01-2005 at 03:18 AM
View Profile Send Email to User Show all user's posts This architect's holds Quote Reply
b0rsuk
Level: Smiter
Avatar
Rank Points: 489
Registered: 11-23-2003
IP: Logged
icon Re: SOS help with ANSI C after 28.II.2005 ! (0)  
As lame as it may be, I decided to ignore segmentation faults. At least for now. After all, it works if parameters are given correctly, and prints helpful message if parameters are incorrect.

I tried to break it into some functions, but failed miserably. And somehow I don't think the way I wrote the code leaves much room for using functions.
I can't really grasp the program as a whole now, not anymore. And all these { } marks just confuse me.

Erik, were you not the one who objected against using fopen and fclose after each line is parsed ? Bad programming style you said.
(fopen before parsing vis line, fclose vis data file after writing).

At the moment I need to devise some kind of system to produce unique numbers from date, day, hour etc to make x coordinates unique. Gnuplot doesn't like two points with same x coordinate.
Fortunatelly I know a bit about binary, octal etc so it's rather simple thing to do.

Then I'll need to set proper x and y ranges for plotting, etc.


____________________________

http://www.gamasutra.com/features/20051128/adams_01.shtml
03-01-2005 at 04:27 PM
View Profile Send Private Message to User Send Email to User Show all user's posts Quote Reply
trick
Level: Legendary Smitemaster
Rank Points: 2580
Registered: 04-12-2003
IP: Logged
icon Re: SOS help with ANSI C after 28.II.2005 ! (+3)  
I noticed that you don't have curly braces around the else part of the if inside the argv for loop in the source you posted above. It isn't actually necessary there since you've only got a single while inside the else, but when you've got such long "lines" it's easy to forget yourself and put extra things before or after the while -- and since there's no braces on the else, all but the first command would always get executed. Maybe you added something there ?

If that isn't the problem, you could do what Erik said, or use a debugger. Sometimes the printfs are enough, but sometimes the extra info a debugger can give you comes in handy. Just compile your program with debug info, and then run your program through the debugger. Since you seem to be using Linux (or some unix, anyway), you could use gdb. Just pass the "-ggdb" switch to the compiler, start gdb with "gdb ./your-program", run your program with "run", and when the segfault appears, gdb will intercept the execution of the program and let you examine what happened and where. Here's some commands to get you started:

set args list of arguments
Set arguments to pass to your program.

run
Starts your program :)

bt
Does a stack backtrace (shows you what functions were called previously).

print variable
Prints the contents of a variable

info args
Shows the arguments passed to the current function

up
Goes up a level on the stack (function called before current, if any).

down
Goes down a level on the stack (function called after current, if any).

c
Continue execution.

quit
Enough! Exit gdb.

As for the x coordinate problem, you could just convert everything into hours (or whatever the least amount of time is).

- Gerry
03-01-2005 at 04:36 PM
View Profile Send Private Message to User Send Email to User Show all user's posts Quote Reply
ErikH2000
Level: Legendary Smitemaster
Avatar
Rank Points: 2794
Registered: 02-04-2003
IP: Logged
icon Re: SOS help with ANSI C after 28.II.2005 ! (+1)  
b0rsuk wrote:
Erik, were you not the one who objected against using fopen and fclose after each line is parsed ? Bad programming style you said. (fopen before parsing vis line, fclose vis data file after writing).
It is bad programming to repeatedly open and close the same while you are still working with it. And also it is bad programming to parse from the beginning of the file for each line. It's just very inefficient and anyone with programming knowledge looking at it would wonder why you didn't parse the file from start to finish in one pass.

Keeping 11 files open when you are only working with 1 or 2 at a time is also poor, and I'll explain why if you want me too. I feel though that a lot of things I'm saying aren't very useful to you. Generally, you want to open a file when you are using it, then close it when you are done.

-Erik

____________________________
The Godkiller - Chapter 1 available now on Steam. It's a DROD-like puzzle adventure game.
dev journals | twitch stream | youtube archive (NSFW)
03-01-2005 at 05:43 PM
View Profile Send Email to User Show all user's posts This architect's holds Quote Reply
b0rsuk
Level: Smiter
Avatar
Rank Points: 489
Registered: 11-23-2003
IP: Logged
icon Re: SOS help with ANSI C after 28.II.2005 ! (+1)  
Ok, so I broke it. And my backup is broken, too. I'm going to start from the source I used above (doesn't print into multiple files).

I'll delete the weather section alltogether. It contains one bug (doesn't register light rain if it's the only weather).
Besides, Gnuplot doesn't plot files which have two points at same x coordinate. So if I REALLY want to show what weather there was (most of the time none), and want to show it even when there are 2 at same time, i have to create one extra data file. Forget it, I'm not doing it. Thre's little weather data anyway.

I'll use x++ as x coordinate. THEN, if it works, I _may_ change it to print actual date. I need to kill all bugs first.


#include <stdio.h>
#include <string.h>

/*clear sky*/
#define vis1 0
#define vis2 1
#define vis3 2
#define vis4 3
#define maxl 80

/*mist*/
#define wea1 0
/*fog*/
#define wea2 1
/*freezing fog*/
#define wea3 2
/*shallow fog*/
#define wea4 3
/*patches of fog*/
#define wea5 4
/* light rain, zeby sie odroznialo od zgrai mgiel */
#define wea6 8
/* chmurki, zeby sie odroznialo */
#define wea7 12
/* light rain showers, zeby sie odroznialo od zgrai mgiel */
#define wea8 9

int main(int argc, char *argv[])
{
    int ismiec;
    int rok;
    int miesiac;
    int dzien;
    int godzina;
    int i;
    int x = 0;
/*    char ssmiec[20];    */
    char line[80];
    char word1[20];
    char word2[20];
    char word3[20];
    char csmiec[40];
    
    FILE *pFile;
    FILE *pWdi = fopen("1winddir.dat", "w");
    FILE *pWsp = fopen("2windspd.dat", "w");
    FILE *pVis = fopen("3visibil.dat", "w");
    FILE *pSky = fopen("4sky.dat", "w");
    FILE *pWea = fopen("5weather.dat", "w");
    FILE *pTem = fopen("6tempera.dat", "w");
    FILE *pWic = fopen("7windchi.dat", "w");
    FILE *pDew = fopen("8dewpoin.dat", "w");
    FILE *pHum = fopen("9humidit.dat", "w");
    FILE *pPre = fopen("0pressur.dat", "w");

    for (i = 1; i < argc; i++) {
	pFile = fopen(argv, "r");
	if (pFile == NULL) {
	    printf("Argumenty musza byc poprawnymi nazwami plikow\\n");
printf("1");
	    fclose(pWdi);
	    fclose(pWsp);
	    fclose(pVis);
	    fclose(pSky);
	    fclose(pWea);
	    fclose(pTem);
	    fclose(pWic);
	    fclose(pDew);
	    fclose(pHum);
	    fclose(pPre);
	} else
	    while (fgets(line, maxl, pFile) != NULL) {
	    printf("%s \\n", argv); 
	    if (sscanf(argv[1], "%s",csmiec) == 1) {
		    printf("%s \\n",csmiec);
		    

		}
		/* zczytywanie i przepisywanie wiatru */
		else if (sscanf
		    (line, "Wind: from the %*s (%s degrees) at %s", word1,
		     word2) == 2) {
		    fprintf(pWdi, "%d %s \\n",x, word1);
		    fprintf(pWsp, "%d %s \\n",x, word2);

		}
		/* ...gdy wiatr zmienny */
		else if (sscanf(line, "Wind: Variable at %s", word1) == 1) {
		    fprintf(pWsp,"%d %s \\n",x, word1);
		}
		/* Widocznosc - wiecej niz... */
		else if (sscanf(line, "Visibility: greater than %s", word1)
			 == 1) {
		    fprintf(pVis, "%d %s \\n",x, word1);
		    /* Widocznosc - mniej niz 1 */
		} else if (sscanf(line, "Visibility: less than %s", word1)
			   == 1) {
		    fprintf(pVis, "%d %s \\n",x, word1);
		    /* widocznosc */
		} else if (sscanf(line, "Visibility: %s", word1) == 1) {
		    fprintf(pVis, "%d %s \\n",x, word1);
		    /* niebo */
		} else
		    if ((sscanf
			 (line, "Sky conditions: %s %s", word1,
			  word2) == 2)
			||
			(sscanf
			 (line, "Sky conditions: %s %s", word1, word2)
			 == 1)) {
		    if (strcmp(word1, "clear") == 0)
			fprintf(pSky, "%d %d \\n",x, vis1);
		    else if ((strcmp(word1, "mostly") == 0)
			     && (strcmp(word2, "clear") == 0))
			fprintf(pSky, "%d %d \\n",x, vis2);
		    else if ((strcmp(word1, "partly") == 0)
			     && (strcmp(word2, "cloudy") == 0))
			fprintf(pSky, "%d %d \\n",x, vis3);
		    else if ((strcmp(word1, "mostly") == 0)
			     && (strcmp(word2, "cloudy") == 0))
			fprintf(pSky, "%d %d \\n",x, vis4);
		    else
			printf("Nieznane zachmurzenie");
		    /* pogoda */
		} else
		    if (sscanf
			(line, "Weather: %s %s %s", word1, word2, word3)
			>= 1) {
		    if (strncmp(line, "Weather: mist", 13) == 0) {
			if ((strcmp(word2, "shallow") == 0)
			    && (strcmp(word3, "fog") == 0)) {
			fprintf(pWea, "%d %d \\n",x, wea1);
			fprintf(pWea, "%d %d \\n",x, wea4);
			} 
			else
			fprintf(pWea, "%d %d \\n",x, wea1);
		    }
		    if (strncmp(line, "Weather: fog", 12) == 0)
			fprintf(pWea, "%d %d \\n",x, wea2);
		    if (strncmp(line, "Weather: freezing fog", 21) == 0)
			fprintf(pWea, "%d %d \\n",x, wea3);
		    if (strncmp(line, "Weather: shallow fog", 20) == 0)
			fprintf(pWea, "%d %d \\n",x, wea4);
		    if (strncmp(line, "Weather: patches of fog", 23) == 0)
			fprintf(pWea, "%d %d \\n",x, wea5);
		    if (strncmp(line, "Weather: light rain", 19) == 0) {
			if (strcmp(word3, "showers") == 0)
			    fprintf(pWea, "%d %d \\n",x, wea8);
			else if (strcmp(word3, "mist") == 0) {
			    fprintf(pWea, "%d %d \\n",x, wea6);
			    fprintf(pWea, "%d %d \\n",x, wea1);}
	                else
			    fprintf(pWea, "!!!! %d %d \\n",x, wea6);
		    }
		    if (strncmp
			(line, "Weather: Cumulonimbus clouds observed", 37)
			== 0)
			fprintf(pWea, "%d %d \\n",x, wea7);
		    /* Temperatura w stopniach Fahrenheita, zeby bylo dokladniej */
		} else if (sscanf(line, "Temperature: %s", word1) == 1) {
		    fprintf(pTem, "%d %s \\n",x, word1);
		    /* Windchill jakis... */
		} else if (sscanf(line, "Windchill: %s", word1) == 1) {
		    fprintf(pWic, "%d %s \\n",x, word1);
		    /* Punkt rosy, cokolwiek by to bylo */
		} else if (sscanf(line, "Dew Point: %s", word1) == 1) {
		    fprintf(pDew, "%d %s \\n",x, word1);
		    /* wilgotnosc */
		} else
		    if (sscanf(line, "Relative Humidity: %d%*s", &ismiec)
			== 1) {
		    fprintf(pHum, "%d %d \\n",x, ismiec);
		    /* cisnienie */
		} else
		    if (sscanf(line, "Pressure %*s %*s %*s %*s (%s", word1)
			== 1) {
		    fprintf(pPre, "%d %s \\n",x, word1);
		}

	    }
	    printf("test");
	fclose(pFile);
    }
    fclose(pWdi);
    fclose(pWsp);
    fclose(pVis);
    fclose(pSky);
    fclose(pWea);
    fclose(pTem);
    fclose(pWic);
    fclose(pDew);
    fclose(pHum);
    fclose(pPre);

    return 0;
}


[Edited by b0rsuk at Local Time:03-01-2005 at 06:04 PM]

____________________________

http://www.gamasutra.com/features/20051128/adams_01.shtml
03-01-2005 at 06:02 PM
View Profile Send Private Message to User Send Email to User Show all user's posts Quote Reply
b0rsuk
Level: Smiter
Avatar
Rank Points: 489
Registered: 11-23-2003
IP: Logged
icon Re: SOS help with ANSI C after 28.II.2005 ! (0)  
Any thoughts about what NOT to do this time ?

____________________________

http://www.gamasutra.com/features/20051128/adams_01.shtml
03-01-2005 at 06:08 PM
View Profile Send Private Message to User Send Email to User Show all user's posts Quote Reply
ErikH2000
Level: Legendary Smitemaster
Avatar
Rank Points: 2794
Registered: 02-04-2003
IP: Logged
icon Re: SOS help with ANSI C after 28.II.2005 ! (0)  
B0rsuk, I didn't understand that you needed to write separate gnuplot files for different elements from the meteo file. Given that, it does make sense to open all the files at the beginning for writing.

Any thoughts about what NOT to do this time ?

Well, you mentioned one problem in the previous post, but you decided not to worry about it. What else is giving you trouble?

-Erik




____________________________
The Godkiller - Chapter 1 available now on Steam. It's a DROD-like puzzle adventure game.
dev journals | twitch stream | youtube archive (NSFW)
03-01-2005 at 07:14 PM
View Profile Send Email to User Show all user's posts This architect's holds Quote Reply
b0rsuk
Level: Smiter
Avatar
Rank Points: 489
Registered: 11-23-2003
IP: Logged
icon Re: SOS help with ANSI C after 28.II.2005 ! (0)  
I just left the temperature like that.

Now I'm using gnuplot for windows,and with help of some tutorials I managed to plot the data. I have no idea if the data is correct, but the graph is done.

Now the stuff like labels etc.

So it can be said that the program is crude, but it works. One thing bothers me - I was getting "bad x range" error in linux gnuplot. I'll write simple separate program to create simple .plt files. One program for preparing data, another for display settings...

Then I should start writing comments to the program, and print it. There's no time, really.

____________________________

http://www.gamasutra.com/features/20051128/adams_01.shtml
03-01-2005 at 08:11 PM
View Profile Send Private Message to User Send Email to User Show all user's posts Quote Reply
b0rsuk
Level: Smiter
Avatar
Rank Points: 489
Registered: 11-23-2003
IP: Logged
icon Re: SOS help with ANSI C after 28.II.2005 ! (0)  
Ok, so I wrote program description and comments, and printed it. I'll pass it to right person tommorow.

It basically does what it's supposed to do, but yes, is crude. I used data to create plots and it seemed fine at first glance.
If the program's going to be rejected, there's no more hope for me. I'll lose another year, and they probably won't allow me to this university another time because I didn't make very good impression. All this papers written,hard work, beaurocracy, and money I earned myself - in vain ? :(

As for today, I decided to play Crimsonland untill I fall unconscious.

[Edited by b0rsuk at Local Time:03-01-2005 at 10:38 PM]

____________________________

http://www.gamasutra.com/features/20051128/adams_01.shtml
03-01-2005 at 10:37 PM
View Profile Send Private Message to User Send Email to User Show all user's posts Quote Reply
ErikH2000
Level: Legendary Smitemaster
Avatar
Rank Points: 2794
Registered: 02-04-2003
IP: Logged
icon Re: SOS help with ANSI C after 28.II.2005 ! (0)  
b0rsuk wrote:
It basically does what it's supposed to do, but yes, is crude. I used data to create plots and it seemed fine at first glance.
If the program's going to be rejected, there's no more hope for me. I'll lose another year, and they probably won't allow me to this university another time because I didn't make very good impression. All this papers written,hard work, beaurocracy, and money I earned myself - in vain ? :(
Well, buddy you definitely tried. Your deadline crisis is what I go through three or four times a year as a programmer, BTW. "The publisher needs the game code complete by Monday morning or we lose the contract!!!!!!" ...and five 16 hour days later, after killing myself to get it just 90% done, it gets sent to the publisher with a few problems left, and then somehow I am extended the "gift" of three more days to fix up remaining problems when really I am due for about 3 days of solid sleep. Bleh. This is the world of software engineering, particularly in the game industry.

Anyhow, I really do wish you luck, and good or bad, could you post back and tell us how it went? If you get kicked out of the school for some reason... well, that will really suck.

-Erik

____________________________
The Godkiller - Chapter 1 available now on Steam. It's a DROD-like puzzle adventure game.
dev journals | twitch stream | youtube archive (NSFW)
03-01-2005 at 11:26 PM
View Profile Send Email to User Show all user's posts This architect's holds Quote Reply
b0rsuk
Level: Smiter
Avatar
Rank Points: 489
Registered: 11-23-2003
IP: Logged
icon I survived (+1)  
Hi

I just wanted to say that 4 hours ago my program has been accepted. A hour later I checked by inbox.

I have to say I'm very grateful for your help. Now it's the right time to do so because there won't be any suprises. Now I'm done with C, for a long time probably.
We started Java 1.5week ago, but I believe I won't have such problems now that we start from beginning.

The whole mess was caused by fact that I didn't notice small handwriting on one of my papers. There was lots of it, mostly meaningless to me like "I need opinion of X"
To tell the truth, even if I noticed it early, the same situation would happen most probably. I'm a master of postponing.

I'm going to make you tasty new hold once JTRH is out. There are some features there that make some things much easier, for example I would no longer have to use zillions of checkpoints to mark squares seen by eyes in one particular room. I'll use another kind of floor tiles.


____________________________

http://www.gamasutra.com/features/20051128/adams_01.shtml
03-02-2005 at 05:42 PM
View Profile Send Private Message to User Send Email to User Show all user's posts Quote Reply
ErikH2000
Level: Legendary Smitemaster
Avatar
Rank Points: 2794
Registered: 02-04-2003
IP: Logged
icon Re: I survived (0)  
b0rsuk wrote:
I just wanted to say that 4 hours ago my program has been accepted. A hour later I checked by inbox.
So they looked at it and decided it was good enough? That's great news! It would be pretty sad after all that work if you didn't make it. I hope you like the Java stuff. You should at least get less segment faults because Java protects you from accessing memory. :)

-Erik

____________________________
The Godkiller - Chapter 1 available now on Steam. It's a DROD-like puzzle adventure game.
dev journals | twitch stream | youtube archive (NSFW)
03-02-2005 at 06:50 PM
View Profile Send Email to User Show all user's posts This architect's holds Quote Reply
Maurog
Level: Smitemaster
Avatar
Rank Points: 1501
Registered: 09-16-2004
IP: Logged
icon Re: I survived (0)  
ErikH2000 wrote:
You should at least get less segment faults because Java protects you from accessing memory. :)
You may think it's a good thing now, but wait till you find out that when things do go wrong, it's close to impossible to track what exactly and where exactly happened, because it's buried deep in those system functions that among other things protect you from accessing memory :|

____________________________
Slay the living! Raise the dead!
Paint the sky in crimson red!
03-02-2005 at 07:11 PM
View Profile Send Private Message to User Send Email to User Show all user's posts Quote Reply
b0rsuk
Level: Smiter
Avatar
Rank Points: 489
Registered: 11-23-2003
IP: Logged
icon Re: I survived (+1)  
Well I hardly understand it now, but at first glance it reminds me of Notrium modding. But more complex.

While I studied in evening system (now weekend system), we were supposed to do this program in months, can't remember how many but at least 3 I think. Of course we were supposed to prepare all the makefiles, polished gnuplot settings (it has quite impressive options you know)... I din't really have time to do it back then because I had hard times with math.
Now some of my notes from evening system are transfered, 1 of 3 maths (the one with algorithms, probability, hashing functions etc). I'm also partially done with algebra (I only need to learn theoretics). But the meanest of them all, mathematical analy(i?)si(y?)s (calculating area under curves etc. i think they are called derivatives and integrals) remains.
I also have good marks from english, so now I should have plenty of time to pass every exam in time. And finish that book. And do some modding. :thumbsup

____________________________

http://www.gamasutra.com/features/20051128/adams_01.shtml
03-02-2005 at 07:22 PM
View Profile Send Private Message to User Send Email to User Show all user's posts Quote Reply
trick
Level: Legendary Smitemaster
Rank Points: 2580
Registered: 04-12-2003
IP: Logged
icon Re: I survived (+1)  
Congratulations!

Fun little story, I actually came into a similar situation myself today (or, well, I guess it's yesterday now). Had an obligatory assignment that was due in today, friday the 4th, but until yesterday I thought it the deadline was the 11th (because of a nasty typo in a document), and had put off starting on this thing because of some other stuff. Anyway, if I didn't complete this and deliver a fully working program (written in x86 assembly), I wouldn't be allowed to take the final exam...

So there I was, one day from the deadline, without a single line of code. Or, well, I had some subroutines and such from an earlier assignment, but those were pretty minor. What to do, what to do... ?

Well, start working on it, of course. Duh.

To make a long story short, I did it :). It was actually a lot easier than I thought... I guess the fact that I love coding in assembly helped :P.

Moral of the story: C64 saves your future!
03-04-2005 at 02:37 AM
View Profile Send Private Message to User Send Email to User Show all user's posts Quote Reply
1
Page 2 of 2
New Topic New Poll Post Reply
Caravel Forum : Other Boards : Anything : I survived (with your help)
Surf To:


Forum Rules:
Can I post a new topic? No
Can I reply? No
Can I read? Yes
HTML Enabled? No
UBBC Enabled? Yes
Words Filter Enable? No

Contact Us | CaravelGames.com

Powered by: tForum tForumHacks Edition b0.98.8
Originally created by Toan Huynh (Copyright © 2000)
Enhanced by the tForumHacks team and the Caravel team.