-
June 13th, 2018, 01:21 AM
#1
empty char
An exercise asks to initialize a matrix because afterwards It's necessary to insert words (char by char), so how can I set empty char?
I thought to set in this way:
Newline is not the same thing of empty char! If I print this char I got newline but empty char should print nothing.
but I'm trying to understand if there is way to define char as empty, just for example as for string I use:
-
June 13th, 2018, 02:02 AM
#2
-
June 13th, 2018, 02:04 AM
#3
Re: empty char
But what exactly is your code?
is not a word, but a letter.
What exactly are you trying?
-
June 13th, 2018, 05:36 AM
#4
Re: empty char
Word is only a identifier and the name is wrong.
I'd like to reset matrix before to write it some characters, so I need to write on each element null value.
So It's correct to write this one ?
-
June 13th, 2018, 06:12 AM
#5
Re: empty char
How is the matrix defined? There are probably ways of initializing it without setting each value.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
June 13th, 2018, 09:26 AM
#6
Re: empty char
Originally Posted by 2kaud
How is the matrix defined?
matrix is defined as NxN according to:
Code:
char** matrix;
matrix=new char*[N];
for (int i=0; i<N; i++)
matrix[i]=new char[N];
-
June 13th, 2018, 10:07 AM
#7
Re: empty char
To create and initialise each element to its default init value (\0 for a char), consider
Code:
auto matrix = new char*[N];
for (int i = 0; i < N; ++i)
matrix[i] = new char[N] {};
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|