Go to the Home Page
C Language
Ladder Language (LD):PLC
Visual Studio ShortCuts:
Ctrl + .
Ctrl + K , Ctrl + D
Ctrl + K , Ctrl + F
Alt + ⬆
Alt + ⬇
Ctrl + B : Build project
Ctrl + Shift + B : Build Solution
Ctrl + F5 : Execute
Ctrl +F7 : Compile
F9: Set/Remove toggle breakpoint
F5: Start Debugging
F10: Step over
F11: Step into
Shift + F11: Step Out.
Ctrl + Shift + F9: Enable/Disable All Breakpoints.
Ctrl + Alt + B: View All Breakpoints.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <Windows.h> beep()
#include <time.h>
Disable Error Setting:
Project -> properties -> Configuration Properties -> C/C++ ->Advanced ->Disable Specific Warnings -> edit ->error NO.
Building only one *.c file
*.c -> properties -> Configuration Properties -> General -> Excluded From Build
conditional operator
condition ? value_if_true : value_if_false;
int max = n1 > n2 ? n1 : n2;
pirntf("%d", n1 > n2 ? n1 - n2 : n2 - n1);
#include <stdio.h>
int main(void)
{
printf("%d", 15 + 37);
return 0;
}
#include <stdio.h>
int main(void) {
int a, b, c, d, e;
scanf_s("%d", &a);
scanf_s("%d", &b);
scanf_s("%d", &c);
scanf_s("%d", &d);
e = (a < b) ?
((a < c) ? a : c) : ((b < c) ? b : c);//biggest number
e = (a < b) ?
((a < c) ? ((a < d) ? a : d) : ((c < d) ? c : d)) :
((b < c) ? ((b < d) ? b : d) : ((c < d) ? c : d));//smallest number
e = a < b ? a < c ? a < d ? a : d : c < d ? c : d : b < c ? b < d ? b : d : c < d ? c : d;//smallest number
e = (a < b) ? a : b;
e = (e < c) ? e : c;
e = (e < d) ? e : d;
printf("%d", e);
return 0;
}
a==b==c -> First evaluate a==b,then evaluate 1==c or 0==c
#include <stdio.h>
int main(void) {
printf("%c %d %d %d", 'A', 'A',sizeof('A'),sizeof("AA"));
return 0;
}
-----------------------------------
result : A 65 4 3
character set :
#include <stdio.h>
int main() {
char str[100];
printf("Enter a line: ");
scanf("%[^\n]", str); // "Match all strings, excluding newline characters (\n)."
printf("You entered: %s\n", str);
return 0;
}
01/10/25 chap04 while
printf("%d",i--);//printf i first , then --
printf("%d",--i);//-- first , then printf i
01/24/25
'\0' == NULL
'A' == 65 == 0x41
printf("%c\n", '\x24');
void str_dcount(const char s[],int cnt[]) {
int i = 0;
while (s[i])
{
if (s[i] >= '0' && s[i <= '9']) {
cnt[s[i] - '0']++;
//s[i] >= 0x30 && s[i] <= 0x39;
//s[i] >= 48 && s[i] < 57;
//cnt[s[i] - 0x30]++;
//cnt[s[i] - 48]++;
}
i++;
}
printf("%c\n", '\x24');
if (s[i++] == c)
char* mymalloc() {
char* pstr = (char*)malloc(6 * sizeof(char));
if (pstr == NULL)
{
printf("failed");
return NULL;
}
return pstr;
}
int str_len(const char* str) {
int len = 0;
while (str[len]!=NULL)
{
len++;
}
return len;
}
01/28/25
void set_idx(int* v, int n) {
for (int i = 0; i < n; i++,v++)
*v= i;
// 1:for (int i = 0; i < n; i++)v[i] = i;
/* 2:
int i = 0;
while (i < n){*v++ = i++;}
*/
}
fp1 = fopen("test1.txt", "r");
fp2 = fopen("test2.txt", "w");
if (fp1 == NULL)
{
printf("1 open failed!\n");
return -1;
}
if (fp2 == NULL)
{
printf("2 open failed!\n");
return -2;
}
while (fscanf(fp1, "%d%s%d", &no, name, &age) == 3)
{
printf("NO.=%d name=%s age=%d\n", no, name, age);
fprintf(fp2, "%d,%s,%d\n", no,name,age);
}
fclose(fp1);
fclose(fp2);
unsigned long long date = 0x123456789ABCDEF0ULL;
unsigned long long* p1 = &date;
unsigned long* p2 = (unsigned long*)&date;
unsigned int* p3 = (unsigned int*)&date;
unsigned short* p4 = (unsigned short*)&date;
unsigned char* p5 = (unsigned char*)&date;
printf("&date=0x%p, 0x%llx\n", &date, date);
printf("p5=0x%p, 0x%hhx\n", p5, *p5);
printf("p4=0x%p, 0x%hx\n", p4, *p4);
printf("p3=0x%p, 0x%x\n", p3, *p3);
printf("p2=0x%p, 0x%lx\n", p2, *p2);
printf("p1=0x%p, 0x%llx\n", p1, *p1);