Hirdetés
- Samsung Galaxy A55 - új év, régi stratégia
- Itt a Galaxy S26 széria: az Ultra fejlődött, a másik kettő alig
- Xiaomi 17 Ultra - jó az optikája
- Samsung Galaxy S23 Ultra - non plus ultra
- Android alkalmazások - szoftver kibeszélő topik
- One mobilszolgáltatások
- Bemutatkozott a Poco X7 és X7 Pro
- OnePlus 15 - van plusz energia
- Milyen okostelefont vegyek?
- Samsung Galaxy S23 és S23+ - ami belül van, az számít igazán
Új hozzászólás Aktív témák
-
Dirty_Pio
csendes tag
Sziasztok, akarok irni egy nagyjabol katalogizalo programot ami eloszor megnyit egy data.txt fielot amiben el vannak mentve a katalogus elemei es a kodjai. A felhasznalo ezutan beirja a kodjat a kivant reszlegnek ami utan a program megnyitja a filet amibe az elemek vannak, es ki is iratja a kepernyore. Ezutan rakerdez hogy akarok-e hozzaadni uj elemet vagy meglevot kitorolni.Minden reszleg, azaz file elso soraba el van mentve hogy hany elem van benne. A problemam az lenne hogy amikor ki akarok torolni egy elemet akkor azt ugy oldalam meg hogy szepen az alatta levo sortol kezdodoen mindent ramasolnak es az utolso sort pedig elhagynam. Itt a kod
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
struct tm * timeinfo;
int rm(FILE *f)
{
fseek(f,0,0);
char buff[255];
int max,linelen,n;
fgets(buff,100,f);
max=atoi(buff);
printf("type the nr of the product");
scanf("%i",&n);
printf("the number %i, and max %i",n,max);
while (n>0)
{
fgets(buff,250,f);
n--;
}
fgets(buff,250,f);
while (fgets(buff,250,f))
{
linelen=strlen(buff);
fseek(f,-linelen,1);
fprintf(f,"%s",buff);
};
return 0;
}
int add(FILE *f)
{
char name[20],price[15],buff[101]="",*s;
int linelen,max;
fseek(f,0,0);
fgets(buff,19,f);
max=atoi(buff);
max++;
// printf("max=%i",max);
fseek(f,0,0);
fprintf(f,"%i\n",max);
fseek(f,0,2);
time_t rawtime;
time(&rawtime);
timeinfo=localtime(&rawtime);
s=asctime(timeinfo);
s[strlen(s)-1]='\0';
fprintf ( f,"\n %i %s ",max,s);
fseek(f,1,1);
gets(buff);
printf("product name:");
scanf("%s",name);
fprintf(f," %s ",name);
printf("product prince:");
gets(buff);
scanf("%s",price);
fprintf(f," %s",price);
return 0;
}
int list(FILE *f)
{
fseek(f,0,0);
char c;
fgetc(f);
while( (c=fgetc(f))!=EOF)
{
putchar(c);
}
printf("\n");
return 0;
}
int main(void)
{
FILE *f,*g;
if (!(g=fopen("data.txt","r"))) {
printf("missing data file");
exit (1);
}
char s[3],c;
int a=1;
list(g);
fclose (g);
while (a)
{
printf("\nchoose the code of the product type\n");
scanf("%s",s);
if (strlen(s)==2)
switch (s[strlen(s)-1])
{
case '1' :
if (!(f=fopen("a1.txt","r+")))
{
printf("missing data file");
exit (1);
}
a=!a;
break;
case '2' :
if (!(f=fopen("a2.txt","r+")))
{
printf("missing data file");
exit (1);
}
a=!a;
break;
case '3' :
if (!(f=fopen("a3.txt","r+")))
{
printf("missing data file");
exit (1);
}
a=!a;
break;
case '4' :
if (!(f=fopen("a4.txt","r+")))
{
printf("missing data file");
exit (1);
}
a=!a;
break;
case '5' :
if (!(f=fopen("a5.txt","r+")))
{
printf("missing data file");
exit (1);
}
a=!a;
break;
case '6' :
if (!(f=fopen("a6.txt","r+")))
{
printf("missing data file");
exit (1);
}
a=!a;
break;
case '7' :
if (!(f=fopen("a7.txt","r+")))
{
printf("missing data file");
exit (1);
}
a=!a;
break;
default :
printf("wrong code\n");
}
}
list(f);
a=1;
while (a)
{
printf("press 1 to add an element, 2 to remove one and 0 to exit");
scanf("%i",&a);
switch(a)
{
case 1:
add(f);
break;
case 2:
rm(f);
break;
default :break;
}
}
fclose (f);
return 0;
}Az rm fuggveny oldana meg a torlest, de ehelyett vegtelen ciklusba kot ki es egyre csak noveli a file meretet. Egy peldat is mellekelek:
file data.txt:
code name
a1 = PC/notebook/server
a2 = cash register/balance
a3 = software
a4 = Husqvarna
a5 = audio systems
a6 = home/car security
a7 = PC/camera accesorriesfile a3.txt
4
nr. __date__ __product_name__ ___price___
1 Mon Oct 05 17:13:14 2009 elem1 1234
2 Mon Oct 05 17:13:22 2009 elem2 3214
3 Mon Oct 05 17:13:28 2009 elem3 2114
4 Mon Oct 05 17:13:33 2009 elem4 2145Es ha tudtok jol fogna egy modszer amivel szepen kozepre tudom amjd igazitani a fielba, mert eddig nekem csak az jutott az eszembe hogy mindig fix szamu karakter keruljon minden nev ala. ELore is kosz.
Új hozzászólás Aktív témák
● olvasd el a téma összefoglalót!
● ha kódot szúrsz be, használd a PROGRAMKÓD formázási funkciót!
- Samsung Galaxy A55 - új év, régi stratégia
- Formula-1
- Assetto Corsa
- WoW avagy World of Warcraft -=MMORPG=-
- Bambu Lab 3D nyomtatók
- Itt a Galaxy S26 széria: az Ultra fejlődött, a másik kettő alig
- One otthoni szolgáltatások (TV, internet, telefon)
- Viber: ingyen telefonálás a mobilodon
- Milyen monitort vegyek?
- Elektromos autók - motorok
- További aktív témák...
- Acer Predator Helios 18 AI I9 ULTRA 9275HX, 192GB RAM, 2TB SSD, RTX 5080
- ÁRGARANCIA!Épített KomPhone i5 14400F 32/64GB RAM RTX 5060 Ti 8GB GAMER PC termékbeszámítással
- HP EliteBook 745 G6 14" Ryzen 5 pro 3500U, 16GB RAM, SSD, jó akku, számla, 6 hó gar
- Dell Latitude 9410 i7 / 16GB RAM / 512GB SSD 2in1 érintőkijelző Profi gép, kedvező áron!
- Beszámítás! HP Elitebook 8 G1i 14 FHD notebook - Ultra 5 235U 16GB DDR5 256GB SSD Intel IGP W11
Állásajánlatok
Cég: Laptopműhely Bt.
Város: Budapest

