1. what do i need to add to "center" my output ?
2. what kind of array do i need to tell how many words & characters & lines are?
thanks!!
CODE
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
// #include <ctype>
#include <iostream>
// #include <vector>
using namespace std;
int isinword(char c) {
return (isalpha(c) || (c==39));
}
void scramble(char* s) {
for(int i = 0; i < strlen(s); i++) {
int position = rand() % strlen(s);
char temp = s[i];
s[i] = s[position];
s[position] = temp;
}
}
int main(int argc, char *argv[]) {
char filename[200];
printf("What's the name of the file: ");
gets(filename);
if(strlen(filename)==0);
strcpy(filename,"scramble.txt");
FILE* f;
f = fopen(filename,"r");
if (!f)
return 1;
char line[1001];
char word[30];
char midword[30];
while (fgets(line,1000,f)) {
int linelen = strlen(line);
for (int i=0;i<linelen;i++) {
if (isinword(line[i])) { // start a word
int start = i;
while (isinword(line[i])) // look for the end of the word
i++;
int end = i;
int wordlen = end-start;
strncpy(word,line+start,wordlen);
word[wordlen] = 0;
if (wordlen > 3) {
strncpy(midword,word+1,wordlen-2);
midword[wordlen-2] = 0;
scramble(midword); // scramble(midword);
strncpy(line+start+1,midword,strlen(midword)); // use strncpy to copy midword back into line at the appropriate place
}
// keep track of # words, word lengths
}
}
printf("%s\n",line);
// print the modified line (center it on the screen)
// keep track of # lines
}
printf("\n\n");
// print summarys
fclose(f);
system("PAUSE");
return 0;
}
This post has been edited by ickiepig: 30 Oct, 2007 - 07:30 PM