bir defada bir sözcük dönüş Bu kod boşluk atlamak ve bir seferde bir kelime dönmek gerekiyordu. Bu kodla ilgili birkaç soru: Kod, * kelimesine ulaştığında ++ = c; hat çekirdek bir dökümü alıyorum. Bu satırı doğru yazdım mı? ve doğrudur. Ve kelimeyi saklamak için bir şekilde bellek ayırmak zorunda mıyım?Atla beyaz boşluk ve C
//get_word
int get_word(char *word,int lim){
int i=0;
int c;
int quotes=0;
int inword = 1;
while(
inword &&
(i < (lim-1)) &&
((c=getchar()) != EOF)
){
if(c==('\"')){//this is so i can get a "string"
if (quotes) {
inword = 0;
}
quotes = ! quotes;
}
else if(quotes){ //if in a string keep storing til the end of the string
*word++=c;//pointer word gets c and increments the pointer
i++;
}
else if(!isspace(c)) {//if not in string store
*word++=c;
i++;
}
else {
// Only end if we have read some character ...
if (i)
inword = 0;
}
}
*word='\0'; //null at the end to signify
return i; //value
}
"malloc" –
@R .. dönüş değerinden almayı kaldırmamın sakıncası olur mu? 'döner' void * ': hata C2440: 'başlatılıyor': 'olmayan'void için işaretçi 'hükümsüz *' den 'char *' Dönüşüm 'hükümsüz *' dan dönüştüremezsiniz @Steve açık döküm" –
gerektirir: Sonra muhtemelen :) – fredoverflow