|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Jun 2002
Città: Milano
Messaggi: 959
|
C e conversione da lettere a binario
devo sviluppare un programma che faccia la compressione dei dati...
mi spiego meglio... ad esempio la lettera A in binario deve essere 00 la lettera B 01 la lettera C 10 ecc ora io avrei bisogno di passare una stringa per esempio ABC e convertirla in questo caso sarebbe 000110 come posso fare??esiste una funzione che mi permetta di tirare fuori le singole lettere da una stringa?? |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
Non hai bisogno di una funzione...c'è già l'operatore []...
stringa[i] von i che va da 0 alla lunghezza della stringa-1 ti fornisce tutte le lettere di una stringa... |
|
|
|
|
|
#3 |
|
Senior Member
Iscritto dal: Nov 2000
Messaggi: 342
|
puoi usare queste:
NAME fgetc, fgets, getc, getchar, gets, ungetc - input of characters and strings SYNOPSIS #include <stdio.h> int fgetc(FILE *stream); char *fgets(char *s, int size, FILE *stream); int getc(FILE *stream); int getchar(void); char *gets(char *s); int ungetc(int c, FILE *stream); DESCRIPTION fgetc() reads the next character from stream and returns it as an unsigned char cast to an int, or EOF on end of file or error. getc() is equivalent to fgetc() except that it may be implemented as a macro which evaluates stream more than once. getchar() is equivalent to getc(stdin). gets() reads a line from stdin into the buffer pointed to by s until either a terminating newline or EOF, which it replaces with '\0'. No check for buffer overrun is performed (see BUGS below). fgets() reads in at most one less than size characters from stream and stores them into the buffer pointed to by s. Reading stops after an EOF or a newline. If a newline is read, it is stored into the buffer. A '\0' is stored after the last character in the buffer. ungetc() pushes c back to stream, cast to unsigned char, where it is available for subsequent read operations. Pushed - back charac- ters will be returned in reverse order; only one pushback is guaranteed. Calls to the functions described here can be mixed with each other and with calls to other input functions from the stdio library for the same input stream. For non-locking counterparts, see unlocked_stdio(3) mentre per il fatto di dover salvare in binario, premetto che qui posso dire un sazzo di cavolate ... NAME fread, fwrite - binary stream input/output SYNOPSIS #include <stdio.h> size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream); size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream); DESCRIPTION The function fread reads nmemb elements of data, each size bytes long, from the stream pointed to by stream, storing them at the loca- tion given by ptr. The function fwrite writes nmemb elements of data, each size bytes long, to the stream pointed to by stream, obtaining them from the location given by ptr. magari attendi qualcuno più esperto di me per maggiori spiegazioni e dettagli Ciao Arpeda
__________________
Membro di HWU Scout Group || Quello che ieri era fantascienza oggi è realtà, quello che oggi è realtà domani sarà solo un ricordo ... Powered by Gentoo 1.4 on kernel 2.6.12.-gentoo-r4 |
|
|
|
|
|
#4 |
|
Senior Member
Iscritto dal: Jun 2002
Città: Milano
Messaggi: 959
|
ci avevo pensato e ho fatto così,però mi da abnormal program termination...sono un pò arrugginito con il C non lo uso da un anno
Codice:
char alfabeto[3]={'A','B','\0'};
int i;
void main(){
clrscr();
for(i=0;i<2;i++){
printf("vado a stampare l'array: %s",alfabeto[i]);
}
getch();
}
|
|
|
|
|
|
#5 |
|
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
%c al posto di %s... alfabeto[i] è un carattere, non una stringa...
|
|
|
|
|
|
#6 |
|
Senior Member
Iscritto dal: Jun 2002
Città: Milano
Messaggi: 959
|
non riesco a trovare una soluzione per cui fare il programma...come potrei farlo??
datemi qualche dritta |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 01:57.



















