Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> การเขียนโปรแกรม C

C program พิมพ์ string โดยไม่ใช้ quotation marks ในโปรแกรม


นี่คือ tricky problem โปรแกรมนี้จะพิมพ์ string โดยไม่มี quotation marks ใดๆ

ใช้ macro function กำหนด macro function เช่น

#define getString(x) #x

getString() เป็น macro function คืน x โดยแปลงเป็น string # นำหน้า x หมายถึง function จะแปลง x เป็น string

Input: Take one string without quote Output: Print that string into console

Algorithm

Step 1:Take a string without quote Step 2: Use macro function to print it into a string Step 3: End

ตัวอย่างโค้ด

#include<stdio.h> #define getString(x) #x //The # will convert x into a string main() { printf(getString(Hello World)); }

Output:

Hello World