Home > Back-end >  Char array contents is assigned to a string variable
Char array contents is assigned to a string variable

Time:03-14

Want to assign the contents of a char array to a string variable, if such write
 
Char Real [128]="F2F10B000001F3";
String sfvalue=https://bbs.csdn.net/topics/RealData;

Will appear this question: [original view]={_Myval2={_Bx={_Buf=0 x0582fb60 viper \ "v" _Ptr=0 x000bf1f2 & lt; Error while reading the string of characters, & gt; _Alias=0 x0582fb60 viper \ "v"} _Mysize=... }}, which is encountered in the process of assignment of 00, just read the error, the final results is sfvalue access only to "F2F10B", later all have no, because 00 on behalf of the end, it should be passed to give a complete array of content to 00 how to solve this problem? For everyone a great god answers

CodePudding user response:

In terms of your statement is only an error
Char Real [128]="F2F10B000001F3";
String sfvalue=https://bbs.csdn.net/topics/RealData;//is RealData, rather than Real

CodePudding user response:

Sorry, that is to write the wrong above, is to get the Real is assigned to a string, the problem is the string '\ 0' end, can't assign the past, that you have a solution?
 
Char Real [128]="F2F10B000001F3";
String sfvalue=https://bbs.csdn.net/topics/Real;

CodePudding user response:

Copy the code does not appear this problem,,

CodePudding user response:

Do you want to many, your string 0 0 are all characters, code value of 0 x30 the east, not to misunderstand,
Suspected cross-border operations elsewhere in your code like you said consequences,

CodePudding user response:

Char Real [128]="F2F10B000001F3";
String sfvalue (Real, Real + len);
  • Related