Hey, I just read your introductory post (cause I wanted to make sure you weren't a filthy spammer before replying).
Welcome to the forums!
Learning to program has a huge learning curve, and you seem to be trying to jump over it. Much like trying to learn multiplication, you absolutely must spend time doing the boring part of memorizing the times tables. For C++, that means working your way through a few really simple and boring tutorials.
Since I am on my mobile I'll just correct the code with short commentary:
[edit]Switched to PC because mobile typing is not fun.[/edit]
#include <cstring>
#include <iostream>
// any time you use anything in code you should check that you have the proper include at the top
// for cout, that's the iostream header
// for strlen(), that's the cstring header
int main()
{
constchar *abc = "((((((a+b)))";
// String literals are encoded as CONSTANTS, so mark them as such.
char *s = newchar[strlen(abc) + 1];
// Here you are creating a pointer (s) and allocating a new collection of characters that you
// can MODIFY, and remembering its location using the pointer s.
// Because strlen() only tells you the length of the string without the trailing null character
// we must add it.
// s = abc;
// Don't do this. abc is a const char* string. s is a char* string. The const-ness matters.
// The problem is that you are setting the POINTER value, NOT copying the string.
// To copy the string, either use a loop, or use the convenient strcpy() function (also
// found in <cstring>. There is plenty of room because we allocated enough for the entire
// abc string plus the null terminator character:
strcpy( s, abc ); // (copies abc to s and returns s)
// for (auto i = 0; i != '\0'; i++)
// Before you were setting i to zero and then terminating when i was equal to zero
// ('\0' is the same as (char)0).
//
// You were also unsure of the type of i. (It is an int.) Only use auto when you are
// dealing with a type you are unsure of / that is complicated and that the compiler
// can resolve for you. In this case, you know what i should be, so auto is unnecessary.
// Correct version 1: using an integer to index the array:
// Indices range from 0 to +N; we stop when we have reached s[N] where s[N] == '\0' == (char)0
for (int i = 0; s[i] != '\0'; i++)
{
std::cout << s[i] << std::endl;
}
std::cout << std::endl; // (added for readability)
// Correct version 2: using a char* to index the array.
for (char* p = s; *p != '\0'; p++)
{
std::cout << *p << std::endl;
}
std::cout << std::endl; // (added for readability)
// Correct version 2, using auto and automatic boolean conversion for the test condition:
for (auto p = s; *p; p++)
{
std::cout << *p << std::endl;
}
// Be sure to deallocate everything you allocate
delete[] s;
}
C:\Users\Michael\foo> cl /EHsc /Ox /std:c++17 /utf-8 a.cpp
...
C:\Users\Michael\foo> a
(
(
(
(
(
(
a
+
b
)
)
)
(
(
(
(
(
(
a
+
b
)
)
)
(
(
(
(
(
(
a
+
b
)
)
)
C:\Users\Michael\foo> _
I compiled using MSVC at the command line
(and skipped copying all the stuff that MSVC prints out)
I then ran the (successfully compiled) program "a.exe"
The first 12 lines are the first loop
The second 12 lines are the second loop
And the third 12 are the third loop