trick wrote:
Moral of the story: Don't use uninitialized memory!
- Gerry
Moral of the story: My head hurts. It's 05:08, I STILL have 3 programs to go. I have to be at university at 08:00.
As far as C server goes, I got (basically) everything to work except "
write to file"
part. It worked if I used putchar instead of fputc, and no amount of tweaking will help. It just the "
odane"
function just eats all input and nothing goes to "
dane"
file. I use put functions because it's supposed to stop at escape character (I use \\e and it works)
int odane(char *gdzie)
{
char ch;
char plik[strlen(gdzie) + 6]; /* 5 za dane */
strcpy(plik, gdzie);
strcat(plik, "/dane");
printf("Test plik3: %s\\n", plik);
FILE *zapis = fopen(plik, "w");
if (zapis != NULL)
{
do {ch = getchar();
fputc(ch, zapis); }
while (ch != '\\e'); return 0;
}
else return 1;
}
int zapukaj(char *gdzie)
{
char plik[strlen(gdzie) + 10]; /* 9 za /lockfile, +1 za znak koncowy */
strcpy(plik, gdzie);
strcat(plik, "/lockfile");
if ((open(plik, O_WRONLY | O_CREAT | O_EXCL, 0666)) == -1) {
return 1;
} else {
close(plik);
return 0;
}
} /*koniec funkcji zapukaj */
int swynik(char *gdzie)
{
char plik[strlen(gdzie) + 7]; /* Dodatek za wyniki */
strcpy(plik, gdzie);
strcat(plik, "/wyniki");
printf("Test plik2: %s\\n", plik);
if ((open(plik, O_WRONLY | O_CREAT | O_TRUNC, 0666)) == -1) {
return 1;
} else {
close(plik);
return 0;
}
}
/* MAIN */
/* MAIN */
/* MAIN */
/* MAIN */
int main(int argc, char *argv[])
{
if (argc != 2) {
printf("Format wywolania: cclient sciezka \\n");
return 1;
}
char ja[strlen(getlogin())];
strcpy(ja, getlogin());
printf("%s\\n", ja);
char sciekli[strlen(ja) + 12]; /* sciezka do roboczego klienta */
strcpy(sciekli, "/home/zaocz/");
strcat(sciekli, ja);
strcat(sciekli, "/tmp");
printf("Test sciekli:%s\\n", sciekli);
/* teraz zajme sie sciezka */
char sciezka[strlen(argv[1]) + 17]; /* 12 bo /home/zaocz/ ma tyle; +4 za /tmp */
strcpy(sciezka, "/home/zaocz/");
strcat(sciezka, argv[1]); /* login osoby z serwerem */
strcat(sciezka, "/tmp"); /* calosc to katalog roboczy SERWERA */
printf("Test - %s \\n", sciezka);
if (swynik(sciekli) == 1) {
printf("Blad przy tworzeniu pliku: wyniki \\n");
return 1;
} else
printf("powstal wynik \\n");
/* Poczatek wlasciwego programu */
while (zapukaj(sciezka) != 0) {
printf("Zajete ! \\n");
sleep(1);
}
printf("Stworzono lockfile - teraz wrzucenie danych\\n");
if (odane(sciezka) == 1) {
printf("Blad przy otwieraniu danych\\n");
return 1;
} else
printf("Dane wrzucone\\n");
odane function is meant to put input where it belongs. The path (plik) is ok, I checked it.
ANyway, you won't repply fast enough,* even assuming you have nothing to do but to search for bugs in my ugly and needlessly long code.
Another C program is supposed to generate N child processes. I tried to do it in a simple loop, but it doesn't stop generating processes. So another failure.
The 3rd program is just sweet - bash calculations with n! thingies, newton thingies (n!)/(k!(n-k)!), and big variables. Several loong hours of "
coding"
wasted.
* so the sole point of this post is to let you know that
MY HEAD HURTS and it won't get better for twenty hours or so.
____________________________
http://www.gamasutra.com/features/20051128/adams_01.shtml
[Last edited by b0rsuk at 11-12-2005 04:28 AM]