This article describes the method for removing whitespace from input lines in C + +. Share to everyone for your reference. The implementation methods are as follows:
* * Delete the spaces and tabs at the end of each input line and delete the line that is entirely blank * * *
#include <stdio.h>
//each row holds no more than 1000 characters, up to 1000 lines
#define MAX 1000
int getline (char line[],int limit);
Main ()
{
int nn;
int i=0,j,k;
Char Line[max];
Char Saveline[max][max];
while (nn = getline (line,max)) > 0) {
if (I < MAX) {for
(j = 0;j < max;j++) {/
* to save the rows that meet the criteria in a two-dimensional array */< C17/>SAVELINE[I][J] = Line[j];
}
i++
}
}
printf ("The New Line is:\n");
for (k = 0;k < i;k++) {
printf ("%s", Saveline[k]);
}
int getline (char vline[],int vlimit)
{
int ch;
int i=0;
int j=0;
while ((ch = getchar ())!= EOF) && (ch!= ' \ n ')) {
if (I < (vlimit-1)) {
vline[j] = ch;
j + +;
}
i++;
}
if (ch = = ' \ n ') {while
(' = = Vline[--j]) | | (' t ' = = Vline[--j]) {
i--;
}
VLINE[J] = ch;
j + +;
i++;
}
VLINE[J] = ' the ';
return i;
}
I hope this article will help you with the C + + program design.