What's new
  • Welcome to PHCorner Forums. Take a moment to Sign up and gain unlimited access and extra privileges that guests are not entitled to, such as: All that and more! Registration is quick, simple and absolutely free. Join our community today!

C masters patulong: Linked Lists: FREE LOAD


pineng

Honorary Poster
Joined
May 31, 2017
Messages
970
Reaction
298
, Last edited:
Patulong po mga master sa C programming:

Given a linked list:
Here I am

H-e-r-e-(space)-I-(space)-a-m-

: Count the number of words in a linked list.
Dapat ang sagot po jan ay 3.
Hmmm, may idea po ba kayo jan kung paano maiimplement?

TIA

Loadan ko po ng 50 makakasagot hehe.
 

laxus456

Honorary Poster
nakagawa ako 2 different files, isang simple lang, nung sa screenshot tapos yung isa nadebug pag maraming space kunyari i __ am ___here (yung underscore ay space, for representation lang), magiging 3 pa rin bilang kahit gano karaming spaces basta may words
 
Comment

homer_simpson

Eternal Poster
Easy:

C:
#include <stdio.h>
#include <stdlib.h>

int main(void) {
    size_t n = 2;
    char* mybuffer = malloc(sizeof(char) + n);
    printf("Enter string: ");
    size_t size = getline(&mybuffer, &n, stdin);
    int count = 0;
     for (int i=0; i<size; i++) {
         if ((mybuffer[i] == ' ' && mybuffer[i+1] != ' ') || mybuffer[i] == '\n') {
             ++count;
         }
     }
     free(mybuffer);
     printf("Num of words: %d\n", count);
     return 0;
}
 
Comment

laxus456

Honorary Poster
Easy:

C:
#include <stdio.h>
#include <stdlib.h>

int main(void) {
    size_t n = 2;
    char* mybuffer = malloc(sizeof(char) + n);
    printf("Enter string: ");
    size_t size = getline(&mybuffer, &n, stdin);
    int count = 0;
     for (int i=0; i<size; i++) {
         if ((mybuffer[i] == ' ' && mybuffer[i+1] != ' ') || mybuffer[i] == '\n') {
             ++count;
         }
     }
     free(mybuffer);
     printf("Num of words: %d\n", count);
     return 0;
}
linked list ba to
 
Comment

pineng

Honorary Poster
nagawa ko na po hehe. Linked lists need sa program eh. for easy deletion and insertion.
 
Comment

Like us on facebook

Online statistics

Members online
766
Guests online
714
Total visitors
1,480

Forum statistics

Threads
880,556
Messages
15,581,577
Members
1,407,230
Top