Setting macros for letters and other symbols in C? [closed] - c

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 11 months ago.
Improve this question
I just wondered, is there a way to define a macro in C to replace it for certain symbols that I print ? I tried something similar to defining number values, like #define NUMBER 7, but I haven't managed to do the same for characters. Googling hasn't given me a proper answer either. Is something like defining characters by macros even a thing in C ? Thanks for your advice !

I believe this is what you are looking for
#include <stdio.h>
#define mystr "HELLO WORLD"
int main()
{
printf("%s", mystr);
return 0;
}

Related

Why doesn't assert do anything? What do I need to do to get it to work? [duplicate]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I have experienced a strange problem when using assert in my program.
The program does not terminate even when I add a line of codeassert(false).
But the assert works when I write several lines of sample code. Anybody know why it happened?
If you have:
#define NDEBUG
this turns all assert's into nop's.
If you have differing behaviour, depending on the amount of code, then I guess you don't have NDEBUG defined and I would guess the compiler is simply compiling out the redundant code.
More details about environment are required, however, you give a definitive answer.

Calculation in C [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I would like to make a simple calculation in C.
Nverthless, there might be a problem in my code with the "resultat"...
Was trying to do the exemple given in OpenClassroom, at the following link : https://openclassrooms.com/fr/courses/19980-apprenez-a-programmer-en-c/14337-une-bete-de-calcul
Here is my code in Repl.
I think the teacher didn't put everything for it to work properly, so I've tried to modificate it by puting the two first lines : https://repl.it/#LunaShivaya/SuburbanThornyDebugmonitor
Thanks in advance for your ideas :)
Sakura.
You need to declare it inside a main function.
#include <stdio.h>
int main()
{
int resultat = 0;
resultat = 5 + 3;
printf("5 + 3 = %d", resultat);
return 0;
}
Libraries are used to load pre-defined variables and functions. In this case, you are using printf, which is pre-defined in the library stdio.h.

C: what's wrong with the code in the image? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I wrote a program to show the capital letter of a given small letter, but in the output console it's showing an error.
#include <stdio.h>
int main
{
char small_letter, capital_letter;
printf("Please enter a small letter: ");
small_letter = getchar();
capital_letter = small_letter - 32;
printf("The capital letter is: %c\n", capital_letter);
return 0;
}
The error seems to indicate you have multiple main functions. It looks like both of your files are being compiled together. In order to compile try renaming or deleting one of your main functions.
To explain a little further this is a linker error caused when the linker is not sure what is meant. In C you can declare functions with the same signature multiple times but you cannot define them multiple times.

Converting a character into a space in C arrays [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
So lets say I have received a message that resembles the following
"L2N5*8R10!11T0A1K3Y14#4W7O6O9C12R13"
and I am expected to sort out the characters in accordance to the numbers succeeding them and change the characters that are not letters into a space. I have no problem doing the sorting out part, I am only having a trouble while trying to write a function that will change those characters into space.
The out put should be something like this
TALK NOW OR CRY
but I am getting
TALK#NOW*OR!CRY
Can anyone help me figure out what my function should look like so that I can be able to change the characters into space??
Unless you show your code, we'll only be able to guess!!
However, as a general suggestion, I would recommended, you should check each entry against isalpha(). In case you got a return value of 0, replace the entry with a .

How do you type something on the same line of text in C [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I was wondering how can you type something in one line in C?
This is the normal way it outputs.
Output
>
<text>
Instead
> <text>
From your tags, I'm guessing you're using printf(). Simply leave out the "\n" character, which means "newline.".
In other words.
printf("> "); printf("text\n");
This will print:
> text

Resources