Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- char * getString(int length){
- /* Returns a string of designated length */
- char *arr = calloc(length,sizeof(char));
- for (int i = 1; i < length; i++){
- scanf("%c",&arr[i]);
- }
- return arr;
- }
- void printString(int strlen, char *string){
- printf("Printing string length: %d\n",strlen);
- for (int i = 0; i < strlen; i++){
- putchar(string[i]);
- }
- putchar('\n');
- }
- void parseString(int strlen, char *string){
- int i = 0;
- int lastSpace = 0;
- while (i < strlen){
- char c = string[i];
- if (c == ' '){
- printString(i-lastSpace,&string[lastSpace]);
- lastSpace = i;
- } else if (i == (strlen-1)){
- printString(strlen-lastSpace, &string[lastSpace]); // Try replacing length with 10, and &string with string
- }
- i++;
- }
- }
- int main(int agrc, char * argv[]){
- /* Get Some String */
- int strlen = 10;
- char *string = getString(strlen);
- parseString(strlen, string);
- /* Obtain */
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement