C + + to remove whitespace in input lines _c language

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.