Hirdetés
- Pixel plus ultra: teszten a 6K-s LG UltraFine monitor
- ThinkPad (NEM IdeaPad)
- Analóg-mechanikus hibrid billentyűzetekkel újít a Logitech
- RAM topik
- Azonnali VGA-s kérdések órája
- Milyen RAM-ot vegyek?
- Nem indul és mi a baja a gépemnek topik
- Projektor topic
- Házimozi belépő szinten
- Felújítva tálalja a száműzötteket az új GeForce driver
Ú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!
- BONTATLAN Új iPhone 17 PRO 256-512GGB Független 1év Apple GARANCIA Deák Térnél Azonnal Átvehető.
- Bomba ár! HP ProBook 430 G3 - i5-6GEN I 4GB I 500GB I HDMI I 13,3" HD I Cam I W10 I Garancia!
- Bomba ár! Lenovo Tablet 10 - Intel N4100 I 8GB I 128SSD I 10,1" WUXGA I HDMI I Cam I W11 I Gari!
- Eladó egy Xiaomi k50 ultra (Xiaomi 12t pro) snapdragon cpu
- Bomba ár! Dell Latitude 3500 - i5-8GEN I 8GB I 256SSD I HDMI I 15,6" HD I Cam I W11 I Gar!
- Apple iPhone 15 Pro / 128GB / Kártyafüggetlen / 12Hó garancia / Akku: 88%
- HIBÁTLAN iPhone 11 64GB Black-2 ÉV GARANCIA - Kártyafüggetlen, MS4634
- Azonnali készpénzes Intel i3 i5 i7 i9 12/13/14 gen processzor felvásárlás személyesen / csomagküldés
- Samsung Galaxy S21 FE 5G 128GB, Kártyafüggetlen, 1 Év Garanciával
- Gravity MS állvány + RØDE XDM-100 Mikrofon!
Állásajánlatok
Cég: Laptopműhely Bt.
Város: Budapest

