Stránka: 2 z 7
| [ Príspevkov: 198 ] | 1, 2, 3, 4, 5 ... 7 |
| Autor | Správa |
|---|
Registrovaný: 08.03.09 Prihlásený: 17.01.25 Príspevky: 1116 Témy: 88 | 88 Bydlisko: 00100100 |
_________________ Programming is The Best
Hackers Are Not Crackers!!! Hackers build things, crackers break them!
;-) |
|
Registrovaný: 30.04.08 Prihlásený: 03.12.25 Príspevky: 884 Témy: 3 | 3 |
Kód: #include <stdio.h>
#define NAZOV "vstup.in"
int main(void) { FILE *fr; char c; int poc = 0;
fr = fopen(NAZOV, "r"); while ((c = getc(fr)) != EOF) poc++; printf("V subore je %d znakov.\n", poc); fclose(fr); return 0; }
_________________ Empty your memory, with a free()… like a pointer! If you cast a pointer to an integer, it becomes the integer, if you cast a pointer to a struct, it becomes the struct… The pointer can crash…, and can overflow… Be a pointer my friend… |
|
Registrovaný: 08.03.09 Prihlásený: 17.01.25 Príspevky: 1116 Témy: 88 | 88 Bydlisko: 00100100 |
anop to viem spravit aj ja ale ja by som to potreboval v C++ pls tam to neviem poimoz pls
a znova to tu dajte dikesssss
_________________ Programming is The Best
Hackers Are Not Crackers!!! Hackers build things, crackers break them!
;-) |
|
Registrovaný: 30.04.08 Prihlásený: 03.12.25 Príspevky: 884 Témy: 3 | 3 |
Ale toto je C++. 
_________________ Empty your memory, with a free()… like a pointer! If you cast a pointer to an integer, it becomes the integer, if you cast a pointer to a struct, it becomes the struct… The pointer can crash…, and can overflow… Be a pointer my friend… |
|
Registrovaný: 08.03.09 Prihlásený: 17.01.25 Príspevky: 1116 Témy: 88 | 88 Bydlisko: 00100100 |
ale neutronmind pls prepis do normalneho C++ nie C++ ktry je cely lôen z C notak ved pomoz 
_________________ Programming is The Best
Hackers Are Not Crackers!!! Hackers build things, crackers break them!
;-) |
|
Registrovaný: 30.04.08 Prihlásený: 03.12.25 Príspevky: 884 Témy: 3 | 3 |
No OK, tak tu to mas s pouzitim triedy ifstream
Kód: #include <fstream>
const char * NAZOV = "vstup.in";
int main(void) { std::ifstream fin; char c; int poc = 0;
fin.open(NAZOV);
while (fin.get(c)) poc++; printf("V subore je %d znakov.\n", poc); fin.close(); return 0; }
_________________ Empty your memory, with a free()… like a pointer! If you cast a pointer to an integer, it becomes the integer, if you cast a pointer to a struct, it becomes the struct… The pointer can crash…, and can overflow… Be a pointer my friend… |
|
Registrovaný: 08.03.09 Prihlásený: 17.01.25 Príspevky: 1116 Témy: 88 | 88 Bydlisko: 00100100 |
diky este jedna prosba nemohol b ysio to dat uplne do C++ aj s iostream a tak a nejakymy komentarmi v tych suboroch som lavy 
_________________ Programming is The Best
Hackers Are Not Crackers!!! Hackers build things, crackers break them!
;-) |
|
Registrovaný: 30.04.08 Prihlásený: 03.12.25 Príspevky: 884 Témy: 3 | 3 |
Kód: #include <fstream> #include <iostream>
const char * NAZOV = "vstup.txt"; //nazov suboru, z ktoreho citame znaky
using namespace std;
int main(void) { ifstream fin; // deklarujeme objekt fin triedy ifstream, pomocou ktoreho budeme pristupovat k suboru a zapisovat do neho char c; int poc = 0;
fin.open(NAZOV); //pouzijeme metodu open() objektu fin, ktorej parametrom je nazov otvoreneho subor, ktory sa otvori na zapis
while (fin.get(c)) //metoda get() sa pouziva na vstup jedneho znaku (ako getchar()), jej volanie vracia hodnotu true, pokial sa citanie podarilo poc++; // ak sme teda nacitali znak, zvysime hodnotu premennej pom, ktora udava pocet znakov v subore //cyklus skonci, ked fin.get()
cout << "V subore je " << poc << "znakov" << endl; // vypiseme, kolko znakov je v subore
fin.close(); // zavrieme subor pomocou metody close() return 0; }
_________________ Empty your memory, with a free()… like a pointer! If you cast a pointer to an integer, it becomes the integer, if you cast a pointer to a struct, it becomes the struct… The pointer can crash…, and can overflow… Be a pointer my friend… |
|
Registrovaný: 08.03.09 Prihlásený: 17.01.25 Príspevky: 1116 Témy: 88 | 88 Bydlisko: 00100100 |
_________________ Programming is The Best
Hackers Are Not Crackers!!! Hackers build things, crackers break them!
;-) |
|
Registrovaný: 30.04.08 Prihlásený: 03.12.25 Príspevky: 884 Témy: 3 | 3 |
Kód: #include <iostream>
using namespace std;
int main(void) { char pom[128]; bool koniec = false;
while (koniec == false) { cin >> pom; if (!strcmp(pom, "q")) koniec = true; }
return 0; }
_________________ Empty your memory, with a free()… like a pointer! If you cast a pointer to an integer, it becomes the integer, if you cast a pointer to a struct, it becomes the struct… The pointer can crash…, and can overflow… Be a pointer my friend… |
|
Registrovaný: 08.03.09 Prihlásený: 17.01.25 Príspevky: 1116 Témy: 88 | 88 Bydlisko: 00100100 |
dakujemdas k tomu komenty pls  pls dakujem
_________________ Programming is The Best
Hackers Are Not Crackers!!! Hackers build things, crackers break them!
;-) |
|
Registrovaný: 30.04.08 Prihlásený: 03.12.25 Príspevky: 884 Témy: 3 | 3 |
Kód: #include <iostream>
using namespace std;
int main(void) { char pom[128]; //tuto budeme docasne ukladat nacitane slova bool koniec = false; //pomocna premenna
while (koniec == false) { cin >> pom; //nacitame do pom nejaky retazec if (!strcmp(pom, "q")) // ak je tento retazec samotne "q" koniec = true; //priradime premennej koniec hodnotu true } // tym padom podmienka v hlavicke cyklu (koniec == false) neplati a cyklus skonci
return 0; }
_________________ Empty your memory, with a free()… like a pointer! If you cast a pointer to an integer, it becomes the integer, if you cast a pointer to a struct, it becomes the struct… The pointer can crash…, and can overflow… Be a pointer my friend… |
|
Registrovaný: 08.03.09 Prihlásený: 17.01.25 Príspevky: 1116 Témy: 88 | 88 Bydlisko: 00100100 |
dikesss 
_________________ Programming is The Best
Hackers Are Not Crackers!!! Hackers build things, crackers break them!
;-) |
|
Registrovaný: 08.03.09 Prihlásený: 17.01.25 Príspevky: 1116 Témy: 88 | 88 Bydlisko: 00100100 |
nemate nejake linky na sranky o kniznici so system("pasue"); napr asi je to v stdlib ze nemte nejake linky ?? djate sem dikess
_________________ Programming is The Best
Hackers Are Not Crackers!!! Hackers build things, crackers break them!
;-) |
|
Registrovaný: 11.01.09 Prihlásený: 01.05.26 Príspevky: 1399 Témy: 10 | 10 Bydlisko: Hrinova | |
Registrovaný: 08.03.09 Prihlásený: 17.01.25 Príspevky: 1116 Témy: 88 | 88 Bydlisko: 00100100 |
dakujem 
_________________ Programming is The Best
Hackers Are Not Crackers!!! Hackers build things, crackers break them!
;-) |
|
Registrovaný: 08.03.09 Prihlásený: 17.01.25 Príspevky: 1116 Témy: 88 | 88 Bydlisko: 00100100 |
neutronmind píše: :) Kód: #include <fstream> #include <iostream>
const char * NAZOV = "vstup.txt"; //nazov suboru, z ktoreho citame znaky
using namespace std;
int main(void) { ifstream fin; // deklarujeme objekt fin triedy ifstream, pomocou ktoreho budeme pristupovat k suboru a zapisovat do neho char c; int poc = 0;
fin.open(NAZOV); //pouzijeme metodu open() objektu fin, ktorej parametrom je nazov otvoreneho subor, ktory sa otvori na zapis
while (fin.get(c)) //metoda get() sa pouziva na vstup jedneho znaku (ako getchar()), jej volanie vracia hodnotu true, pokial sa citanie podarilo poc++; // ak sme teda nacitali znak, zvysime hodnotu premennej pom, ktora udava pocet znakov v subore //cyklus skonci, ked fin.get()
cout << "V subore je " << poc << "znakov" << endl; // vypiseme, kolko znakov je v subore
fin.close(); // zavrieme subor pomocou metody close() return 0; } k tomuto ako bysom do toho zakomponoval EOF ukazes mi viac moznosti kao ho tam dat ?? pls plsp ls dakujem 
_________________ Programming is The Best
Hackers Are Not Crackers!!! Hackers build things, crackers break them!
;-) |
|
Registrovaný: 30.04.08 Prihlásený: 03.12.25 Príspevky: 884 Témy: 3 | 3 |
Volanie fin.get(c) vracia objekt fin. Pokial sa prislo na EOF, po pretypovani vrateneho objektu na bool bude mat vyraz fin.get(c) hodnotu false, teda cyklus skonci.
Mozes vsak spravit aj napr. toto
Kód: while (!fin.eof()) { fin.get(c); poc++; }
Tu pouzijes metodu eof(), ktora vracia true, pokial fin narazil na koniec suboru.
_________________ Empty your memory, with a free()… like a pointer! If you cast a pointer to an integer, it becomes the integer, if you cast a pointer to a struct, it becomes the struct… The pointer can crash…, and can overflow… Be a pointer my friend… |
|
Registrovaný: 08.03.09 Prihlásený: 17.01.25 Príspevky: 1116 Témy: 88 | 88 Bydlisko: 00100100 |
dakujem a co tak neco co porovnava s EOF ako napr c!=EOF neco take nenajde sa?? 
_________________ Programming is The Best
Hackers Are Not Crackers!!! Hackers build things, crackers break them!
;-) |
|
Registrovaný: 30.04.08 Prihlásený: 03.12.25 Príspevky: 884 Témy: 3 | 3 |
Da sa, kedze metoda get objektu fin je pretazena, takze mozes spravit aj nieco taketo
Kód: char c;
while ((c = fin.get()) != EOF) { poc++; }
_________________ Empty your memory, with a free()… like a pointer! If you cast a pointer to an integer, it becomes the integer, if you cast a pointer to a struct, it becomes the struct… The pointer can crash…, and can overflow… Be a pointer my friend… |
|
Registrovaný: 08.03.09 Prihlásený: 17.01.25 Príspevky: 1116 Témy: 88 | 88 Bydlisko: 00100100 |
dakujem za rady a vysvetlenie 
_________________ Programming is The Best
Hackers Are Not Crackers!!! Hackers build things, crackers break them!
;-) |
|
Registrovaný: 08.03.09 Prihlásený: 17.01.25 Príspevky: 1116 Témy: 88 | 88 Bydlisko: 00100100 |
ked chcem spojit ako pri cin takto tak ako to sparvim v subore??
cin.get(g).getline().get(h);
nieco taketo spravim do suboroveho prevedenia takto ??
fin.get(g).getline().get(h);
je to spravne??
a este jedna otazka kde v subre sa zapisuje ako sa tam posuvam a kde sa zacina ciat a pisat do subru?? poradte pls
mozu byt aj linky 
_________________ Programming is The Best
Hackers Are Not Crackers!!! Hackers build things, crackers break them!
;-) |
|
Registrovaný: 30.04.08 Prihlásený: 03.12.25 Príspevky: 884 Témy: 3 | 3 |
reDo píše: ked chcem spojit ako pri cin takto tak ako to sparvim v subore?? cin.get(g).getline().get(h); nieco taketo spravim do suboroveho prevedenia takto ?? fin.get(g).getline().get(h); je to spravne??
Ano. reDo píše: a este jedna otazka kde v subre sa zapisuje ako sa tam posuvam a kde sa zacina ciat a pisat do subru?? poradte pls mozu byt aj linky
Nikde sa to nezapisuje. 
_________________ Empty your memory, with a free()… like a pointer! If you cast a pointer to an integer, it becomes the integer, if you cast a pointer to a struct, it becomes the struct… The pointer can crash…, and can overflow… Be a pointer my friend… |
|
Registrovaný: 08.03.09 Prihlásený: 17.01.25 Príspevky: 1116 Témy: 88 | 88 Bydlisko: 00100100 |
n ozabudol som na ciru asi, preeto to vyznelo blbo malo to byt takto kde sa zapisuje na zacaitku na kónci suboru ako sa v nom posuvam alebo take mozu byt aj linky
_________________ Programming is The Best
Hackers Are Not Crackers!!! Hackers build things, crackers break them!
;-) |
|
Registrovaný: 30.04.08 Prihlásený: 03.12.25 Príspevky: 884 Témy: 3 | 3 |
Musis to otvorit v inom mode, tu ich mas vsetky napisane http://www.cplusplus.com/reference/iost ... ream/open/ - napr. ak chces otvorit subor a zapisovat na koniec, mozes to spravit napr. takto
Kód: fout.open ("vystup.txt", ios_base::app);
Posuvanie v subore - http://www.cplusplus.com/reference/iost ... eam/seekp/
_________________ Empty your memory, with a free()… like a pointer! If you cast a pointer to an integer, it becomes the integer, if you cast a pointer to a struct, it becomes the struct… The pointer can crash…, and can overflow… Be a pointer my friend… |
|
Registrovaný: 08.03.09 Prihlásený: 17.01.25 Príspevky: 1116 Témy: 88 | 88 Bydlisko: 00100100 |
dikes za linky
_________________ Programming is The Best
Hackers Are Not Crackers!!! Hackers build things, crackers break them!
;-) |
|
Registrovaný: 08.03.09 Prihlásený: 17.01.25 Príspevky: 1116 Témy: 88 | 88 Bydlisko: 00100100 |
vysvetlite mi ako funguje strcmp viem ze vracia to tot to ked je to take take take ale co sa stane ked dam predto !strcmp() co potom sa stane??
_________________ Programming is The Best
Hackers Are Not Crackers!!! Hackers build things, crackers break them!
;-) |
|
Registrovaný: 11.08.07 Príspevky: 4088 Témy: 34 | 34 Bydlisko: Brno |
Negacia. Z true bude false a naopak.
A vyjadruj sa zrozumitelnejsie, fakt sa to niekedy po tebe neda lustit.
|
|
Registrovaný: 30.04.08 Prihlásený: 03.12.25 Príspevky: 884 Témy: 3 | 3 |
Hej, totiz strcmp() vracia nulu ak su retazce zadane ako parametre rovnake. Vyraz !strcmp() je ekvivalentny s (strcmp() == 0) 
_________________ Empty your memory, with a free()… like a pointer! If you cast a pointer to an integer, it becomes the integer, if you cast a pointer to a struct, it becomes the struct… The pointer can crash…, and can overflow… Be a pointer my friend… |
|
Registrovaný: 08.03.09 Prihlásený: 17.01.25 Príspevky: 1116 Témy: 88 | 88 Bydlisko: 00100100 |
dakujem uz rozumiem nevedel som ako ta strcmp pracuje 
_________________ Programming is The Best
Hackers Are Not Crackers!!! Hackers build things, crackers break them!
;-) |
|
Stránka: 2 z 7
| [ Príspevkov: 198 ] | 1, 2, 3, 4, 5 ... 7 |
|