[英]how to cast a char array to compare it with unsigned char array?
我正在嘗試使用s2來使測試通過。
我將可打印字符和未簽名的char值一起存儲到s3中。
s2是一個測試字符串結果,旨在驗證可打印的char是否已正確裝入s3中。
#include <stdio.h>
#include <string.h>
#define test_string_len 2
union {
char unsigned us[test_string_len];
char s1[test_string_len];
} result;
main() {
char *s2;
s2= "ab";
char unsigned s3[test_string_len];
s3[0] = 'a';
s3[1] = 'b';
s3[2] = '\0';
memcpy (result.us, s3, test_string_len);
if ( result.s1 == s2) {
printf("Pass\n");
}
printf("s2 = %s\n", s2 );
printf("s3 = %s\n", s3 );
printf("result.s1 = %s\n", s3 );
printf("result.us = %s\n", result.us );
getchar();
}
您需要按以下方式更改代碼。
if(!strcmp( result.s1,s2)) {
printf("Pass\n");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.