Guest_imported
New member
- Jan 1, 1970
- 0
Here is my code. ANY suggestions would be amazing. Basically my question as shown in the subject is that I need some way of taking the data and then stopping after a hundred characters have been read and then go to the next sentence.
#include <stdio.h>
#include <stdlib.h>
int main(void) {
FILE *f;
char filename[80];
char ws;
int k,r,ls;
char word[100][100];
char name[100];
/* get a filename from the user */
printf("Enter a filename to read.\n"
scanf("%s", filename);
/* open a file for input */
if (( f = fopen(filename, "r") == NULL) {
printf("Can't open %s.\n", filename);
exit(1);
}
/* read one character at a time until end-of-file */
for (k=0; k<100;++k){ /*This will fill the array*/
for (r=0;r<100;++r){ /*This will fill the array*/
word[k][r]=getc(f); /*Writes the char into the array*/
ws=word[k][r]; /*Set so ws will equal the array*/
ls=ws;
if (ws=='\n'){ /*checks for new line*/
while (r<100){
word[k][r]=' '; /*this will fill the array if new line is present*/
r=r+1;
}
++k; /*this will move the array*/
r=-1; /*corrects the begining number for r*/
}
if (ls==13){
word[k][r]=' ';
}
if (ws=='.'){ /*checks for end of sentence*/
r=r+1;
while (r<100){
word[k][r]=' '; /*fills loop*/
r=r+1;
}
++k;
r=-1;
}
if (ws=='!'){ /*same as end of sentence but for !*/
r=r+1;
while (r<100){
word[k][r]=' ';
r=r+1;
}
++k;
r=-1;
}
if (ws=='?'){ /*same as end of sentence but for ?*/
r=r+1;
while (r<100){
word[k][r]=' ';
r=r+1;
}
++k;
r=-1;
}
}
}
for (k=0;k<100;++k){
for (r=0; r<100;++r){
printf("%c",word[r][k]); /*THis will print out the columns instead of in rows*/
}
printf("\n"
}
fclose(f);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main(void) {
FILE *f;
char filename[80];
char ws;
int k,r,ls;
char word[100][100];
char name[100];
/* get a filename from the user */
printf("Enter a filename to read.\n"
scanf("%s", filename);
/* open a file for input */
if (( f = fopen(filename, "r") == NULL) {
printf("Can't open %s.\n", filename);
exit(1);
}
/* read one character at a time until end-of-file */
for (k=0; k<100;++k){ /*This will fill the array*/
for (r=0;r<100;++r){ /*This will fill the array*/
word[k][r]=getc(f); /*Writes the char into the array*/
ws=word[k][r]; /*Set so ws will equal the array*/
ls=ws;
if (ws=='\n'){ /*checks for new line*/
while (r<100){
word[k][r]=' '; /*this will fill the array if new line is present*/
r=r+1;
}
++k; /*this will move the array*/
r=-1; /*corrects the begining number for r*/
}
if (ls==13){
word[k][r]=' ';
}
if (ws=='.'){ /*checks for end of sentence*/
r=r+1;
while (r<100){
word[k][r]=' '; /*fills loop*/
r=r+1;
}
++k;
r=-1;
}
if (ws=='!'){ /*same as end of sentence but for !*/
r=r+1;
while (r<100){
word[k][r]=' ';
r=r+1;
}
++k;
r=-1;
}
if (ws=='?'){ /*same as end of sentence but for ?*/
r=r+1;
while (r<100){
word[k][r]=' ';
r=r+1;
}
++k;
r=-1;
}
}
}
for (k=0;k<100;++k){
for (r=0; r<100;++r){
printf("%c",word[r][k]); /*THis will print out the columns instead of in rows*/
}
printf("\n"
}
fclose(f);
return 0;
}