Ceriwis  

Go Back   Ceriwis > HOBI > Komputer & Teknologi > Programming

Programming Share, tanya jawab, saling bantu antar programmer dengan berbagai macam bahasa pemrograman.

Reply
 
Thread Tools
  #1  
Old 11th November 2011
Braincode's Avatar
Braincode Braincode is offline
Ceriwis Addicted
 
Join Date: Nov 2011
Posts: 4,638
Rep Power: 20
Braincode mempunyai hidup yang Normal
Default [ASK][help]tolong koreksiin kodingan c

agan dan aganwati help koreksiin kodingan ini ya



problemnya

INPUT :

sebuah kalimat

OUTPUT:

menampilkan total kata dan huruf dari kalimat tersebut serta menampilkan kata-katanya kembali secara urut berdasarkan panjangnya



jadi misalnya

INPUT : ane suka ngaskus pagi siang malem



OUTPUT:

ane

suka

pagi

siang

malem

ngaskus



code nya lulus compile tp pas lg jalan error (berhenti , trus ada windows error gitu)




Code:

#include
#include
#include
#include
#include

int jumlah_kata(char str[])
{
int i = 0;
int jumlah = 0;

while(str[i]!='')
{
while(isspace(str[i]) || ispunct(str[i]))
i++;
jumlah++;
while(isalpha(str[i]))
i++;
}
return(jumlah);
}

int jumlah_huruf(char str[])
{
int i = 0;
int jumlah = 0;

while(str[i]!='')
{
if(isalpha(str[i]))
{
jumlah++;
i++;
}
else
i++;
}

return(jumlah);
}

void pencacah_kalimat(char str[],char *pkal[])
{
char temp[256];
int i,j,k = 0;

while(str[i]!='')
{
j=0;
while(isspace(str[i]) || ispunct(str[i]))
i++;
while(isalpha(str[i]))
{
temp[j]=str[i];
j++;
i++;
}
temp[jumlah_huruf(temp)]='';
pkal[k]=(char*)malloc((jumlah_huruf(temp)+2)*sizeof(char) );
strcpy(pkal[k],temp);
k++;
}
}



int main(void)
{
char kata[256];
char* pkata[50];
char *ptemp = NULL;
int i , j = 0;

printf("Masukkan sebuah kalimat\n");
gets(kata);

printf("kalimat yg dikeik memiliki %d kata dan %d huruf",jumlah_kata(kata),jumlah_huruf(kata));

pencacah_kalimat(kata,pkata);

for(i=0;i

Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


 


All times are GMT +7. The time now is 09:38 PM.


no new posts