0
I made a program of space remover in string but it only work in stdio header file not in iostrem ?
15 odpowiedzi
+ 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.
+ 1
#include<stdio.h> is used in C
#include<iostream> is used in C++
What is your program written in?
+ 1
Provide your code so we can help more
:)
+ 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;
}
0
C++
0
I used iostream but it shows error of using fgets istead of gets function
0
Ankit Chaturvedi just like Chirag Kumar said, post your code for a quick solution.
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;
}
0
When i am running this code it is taking input
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.
0
Can you post your code for better under standing
0
It is also showing error If i did not use string header file
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).
0
I did not understand
0
Can you correct the above code?