63 123
Assignments Done
99%
Successfully Done
In July 2018

Answer to Question #34127 in C++ for Kady

Question #34127
how am i supposed to remove all leading and trailing whitespaces from an array? please give me some logic so i can work on it! :)
Expert's answer
#include <cctype>
#include <stdio.h>
#include <cstdlib>
#include <string.h>
#include <iostream>


using namespace std;


const int N = 100;


char array[N];
char arr[N];


int main () {
gets(array);
strcpy(arr, array);
int k = 0;
int array_length = strlen(array);
while (k < array_length && isspace(arr[k])) ++k;//find number of white spaces
for (int i = k; i <= array_length; i++)
arr[i - k] = arr[i];
printf("%s
", arr);
cin.get();
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions