I made a program of space remover in string but it only work in stdio header file not in iostrem ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I made a program of space remover in string but it only work in stdio header file not in iostrem ?

12th Nov 2019, 12:58 PM
Ankit Chaturvedi
Ankit Chaturvedi - avatar
15 Answers
+ 1
You already have <str> declared at first line: char str[100] And a few lines down you try to assign a char pointer to a char: str[100] = "your welcome"; ↑ ↑ char char pointer * I haven't thoroughly checked the rest of the code.
12th Nov 2019, 2:20 PM
Ipang
+ 1
#include<stdio.h> is used in C #include<iostream> is used in C++ What is your program written in?
12th Nov 2019, 1:01 PM
Avinesh
Avinesh - avatar
+ 1
Provide your code so we can help more :)
12th Nov 2019, 1:04 PM
Chirag Kumar
Chirag Kumar - avatar
+ 1
Have you figured it out? Here's an edited version of your code, tested in Playground. #include <iostream> //#include<string.h> using namespace std; int main() { char str[100] = "You are welcome!", gt[100]; for(int i = 0, j = 0; i < 100; i++) { if(str[i] != ' ') { gt[j++] = str[i]; } } cout << str << endl << gt << endl; return 0; }
12th Nov 2019, 4:15 PM
Ipang
0
C++
12th Nov 2019, 1:03 PM
Ankit Chaturvedi
Ankit Chaturvedi - avatar
0
I used iostream but it shows error of using fgets istead of gets function
12th Nov 2019, 1:06 PM
Ankit Chaturvedi
Ankit Chaturvedi - avatar
0
Ankit Chaturvedi just like Chirag Kumar said, post your code for a quick solution.
12th Nov 2019, 1:07 PM
Avinesh
Avinesh - avatar
0
#include <iostream> #include<string.h> using namespace std; int main() {char str[100],gt[100]; int i,j=0; str[100]="your welcome"; str[99]='\0'; for(i=0;i<100;i++) { if(str[i]!=' ') { gt[j]=str[i]; j++; } } for(i=0;i<100;i++) { cout<<gt[i]; } return 0; }
12th Nov 2019, 1:12 PM
Ankit Chaturvedi
Ankit Chaturvedi - avatar
0
When i am running this code it is taking input
12th Nov 2019, 1:13 PM
Ankit Chaturvedi
Ankit Chaturvedi - avatar
0
Ankit Chaturvedi A quick important point. Don't use gets cause most of the compiler which uses gcc/c++ based compiler will give you error because standard c++ or you can say new c++ tells that using gets is unsecure instead use fgets. Syntax for fgets is: char* fgets(char* str,int count,FILE* stream); Your code is perfect but might be possible that sololearn c++ compiler based on new gcc/c++ don't support gets use fgets instead.
12th Nov 2019, 1:13 PM
Chirag Kumar
Chirag Kumar - avatar
0
Can you post your code for better under standing
12th Nov 2019, 1:15 PM
Ankit Chaturvedi
Ankit Chaturvedi - avatar
0
It is also showing error If i did not use string header file
12th Nov 2019, 2:23 PM
Ankit Chaturvedi
Ankit Chaturvedi - avatar
0
But I didn't see any function from string header file. I tried to comment the header #include line, and it works (with modification I mean).
12th Nov 2019, 2:29 PM
Ipang
0
I did not understand
12th Nov 2019, 2:31 PM
Ankit Chaturvedi
Ankit Chaturvedi - avatar
0
Can you correct the above code?
12th Nov 2019, 2:32 PM
Ankit Chaturvedi
Ankit Chaturvedi - avatar