I wrote a code but I have not to result.
'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
I need to change all. on ...
#include <iostream>
using namespace std;
int main()
{
char str[50];
int i, j;
char str2[50];
int d;
cin >> str[50];
j = 0;
d = strlen(str);
for (i = 0; i < d; i++)
if (i < d - 2)
{
if ((str[i] == '.') && (str[i + 1] == '.') && (str[i + 2] == '.'))
{
str2[j++] = '.';
i += 2;
}
else
{
str2[j++] = str[i];
}
}
else
{
str2[j++] = str[i];
}
#include <iostream>
usingnamespace std;
int main()
{
char str[50];
int i, j;
char str2[50];
int d;
cin >> str[50];
j = 0;
d = strlen(str);
for (i = 0; i < d; i++) //<-- this for loop is missing open and close braces.
if (i < d - 2)
{
if ((str[i] == '.') && (str[i + 1] == '.') && (str[i + 2] == '.'))
{
str2[j++] = '.';
i += 2;
}
else
{
str2[j++] = str[i];
}
}
else
{
str2[j++] = str[i];
}
str2[j] = '\0';
strcpy(str, str2);
// where is the closing brace for the main function?
you need to either get a IDE that does formatting for you and learn how to indent properly or you will end up doing this more often.
There is so much wrong with this code what are you even trying to do?
1 2 3 4
cin >> str[50]; // <-- this here is also a problem.
// you are trying to assign the input to and element that does not exist!
// you declared a char array of 50 elements above so the range of indices you have is from 0 - 49.
// you can't assign past element 49 of the array!
I don't think this is what is meant. This defines a char array with 50 elements (0 - 49) and then input a character into element 50 - out of bounds for the char array.