Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [C] wczytywanie z pliku na ekran
maciu
post 3.06.2004, 18:40:56
Post #1





Grupa: Zarejestrowani
Postów: 238
Pomógł: 1
Dołączył: 27.08.2003

Ostrzeżenie: (0%)
-----


w pliku tekstowym mam wypisane liczby(cyfry) oddzielone od siebie spacjami. Jak napisać funkcję, która wczytuje na ekran każdą z tych liczb(cyfr), gdzie każda liczba będzie w nowej lini?
Go to the top of the page
+Quote Post
Jabol
post 3.06.2004, 19:25:52
Post #2





Grupa: Przyjaciele php.pl
Postów: 1 467
Pomógł: 13
Dołączył: 22.02.2003

Ostrzeżenie: (0%)
-----


Kod
#include<stdio.h>

int int_out(FILE *fp)

{

    int c, i=0, buf[30];

    memset(buf, 0, 30);

    while((c=fgetc(fp))!=EOF)

    {

        if(c==' ') break;

        if(i < 30) buf[i++]=c;

            else break;

    }

    printf("%dn", buf);

    if(feof(fp)) return 0;

    return 1;

}
powinno działać (nie wiem, pisze z głowy)....
Go to the top of the page
+Quote Post
matys
post 3.06.2004, 19:28:12
Post #3





Grupa: Zarejestrowani
Postów: 109
Pomógł: 0
Dołączył: 7.03.2004
Skąd: Szczecin|Bukowe

Ostrzeżenie: (0%)
-----


Ja to napisałem tak:
Kod
#include <iostream>

#include <stdlib.h>



using namespace std;



int main()

{

    int i;

    int tablica[6]={1, 2, 3, 4, 5, 6};

    

    for(i=0; i<=5; i++)

  {

  cout << tablica[i] << "n";

  }

  system("PAUSE");    

  return 0;

}


--------------------
"Unix is like a vigvam - no windows, no gates, Apache inside"
Warsztat: Windows XP PE | Dreamweaver | Apache 1.3.29 | PHP 4.3.4 | Araneae | MYSQL 4 | Visual Studio | Dev-C++
[b]Programowanie: llllll 40%
Go to the top of the page
+Quote Post
MaKARON
post 3.06.2004, 20:23:57
Post #4





Grupa: Zarejestrowani
Postów: 114
Pomógł: 1
Dołączył: 17.07.2003

Ostrzeżenie: (0%)
-----


Cytat
Ja to napisałem tak:
Kod
using namespace std;

Ale to juz c++ smile.gif
Go to the top of the page
+Quote Post
maciu
post 3.06.2004, 21:04:38
Post #5





Grupa: Zarejestrowani
Postów: 238
Pomógł: 1
Dołączył: 27.08.2003

Ostrzeżenie: (0%)
-----


Cytat
Kod
#include<stdio.h>

int int_out(FILE *fp)

{

    int c, i=0, buf[30];

    memset(buf, 0, 30);

    while((c=fgetc(fp))!=EOF)

    {

        if(c==' ') break;

        if(i < 30) buf[i++]=c;

            else break;

    }

    printf("%dn", buf);

    if(feof(fp)) return 0;

    return 1;

}
powinno działać (nie wiem, pisze z głowy)....


co oznacza memset(buf, 0, 30);
Go to the top of the page
+Quote Post
Cudi
post 3.06.2004, 21:49:25
Post #6


Administrator planeta/IRC


Grupa: Przyjaciele php.pl
Postów: 385
Pomógł: 0
Dołączył: 19.04.2003
Skąd: Zabrze

Ostrzeżenie: (0%)
-----


Cytat
void *memset(void *s, int c, size_t n);
Funkcja memset() wypełnia pierwsze n bajtów obszaru pamięci wskazywanego przez s stałym bajtem c.


--------------------
"Programmers are in a race with the Universe to create bigger and better idiot-proof programs, while the Universe is trying to create bigger and better idiots. So far the Universe is winning."
Cudi's devBlog
Go to the top of the page
+Quote Post
matys
post 4.06.2004, 12:55:20
Post #7





Grupa: Zarejestrowani
Postów: 109
Pomógł: 0
Dołączył: 7.03.2004
Skąd: Szczecin|Bukowe

Ostrzeżenie: (0%)
-----


Oj przepraszam nie doczytałem i moj kod jest w C++, ale i tak sie może przydać;)


--------------------
"Unix is like a vigvam - no windows, no gates, Apache inside"
Warsztat: Windows XP PE | Dreamweaver | Apache 1.3.29 | PHP 4.3.4 | Araneae | MYSQL 4 | Visual Studio | Dev-C++
[b]Programowanie: llllll 40%
Go to the top of the page
+Quote Post
Jabol
post 4.06.2004, 14:55:46
Post #8





Grupa: Przyjaciele php.pl
Postów: 1 467
Pomógł: 13
Dołączył: 22.02.2003

Ostrzeżenie: (0%)
-----


aha, i oczywiście moją funkcję należy wstawić w pętle:
Kod
FILE *fp=fopen('liczby.txt');

while(int_out(fp));
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 19.07.2025 - 09:57