04-01-2012, 18:16
|
מנהל מולטימדיה
|
|
חבר מתאריך: 07.12.07
הודעות: 1,955
|
|
למה לנסות להסביר במילים? זו הייתה הכוונה.
קוד:
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
void main(){
char sent[256*256];
char **wordArr;
int sentIndex = 0;
int wordIndex = 0;
int wordCounter = 0;
fgets(sent, sizeof(sent), stdin);
while(sent[sentIndex++]) if(sent[sentIndex] == ' ') wordCounter++;
wordCounter++;
sentIndex = 0;
printf("There Are %d Words In The Sent\n", wordCounter);
// Initalizing the array of WORDS
wordArr = (char **)malloc(sizeof(char *)*wordCounter);
// Filling the array of WORDS
wordArr[0] = sent;
while(sent[sentIndex]){
if(sent[sentIndex] == ' ') {
sent[sentIndex] = NULL;
wordArr[++wordIndex] = &sent[sentIndex+1];
}
sentIndex++;
}
// Printing the array of WORDS
for(int i=0;i<wordCounter;i++)
printf("%s ", wordArr[i]);
system("PAUSE");
}
_____________________________________
|