MFC中listBox输出**烫烫烫**乱码

wuzhi11love 2011-07-11 10:59:58
我有一段代码,想将www.renren.com显示在MFC的listBox里面,用下面的代码得到的是

Host:www.renren.烫烫烫烫烫烫烫烫,
我希望得到www.renren.com,为什么会输出Host:和烫烫烫烫烫?
char *tmpCh="Host: www.renren.com

demonbug=&email=15951983657&password=19921231&origURL=http%3A%2F

%2Fwww.renren.com%2Fhome&domain=renren.com";
char tmp_content[50];
char *pos1=NULL;
char *pos2=NULL;

pos1=strstr(tmpCh,"Host:");
pos1=pos1+4;
pos2=strstr(tmpCh,"demonbug");
strncpy(tmp_content,tmpCh,pos2-pos1);

SendMessage(GetDlgItem

(hwnd,IDC_LIST1),LB_INSERTSTRING,0,(LPARAM)tmp_content);
...全文
331 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
c_losed 2011-07-11
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 wuzhi11love 的回复:]

引用 1 楼 c_losed 的回复:

木有结束符C/C++ code

char tmp_content[50] = {0};

乱码的问题解决了,可是怎么输入www.renren.com呢?我上面的方法输出的总是有Host:
[/Quote]

strncpy(tmp_content,tmpCh+5,pos2-pos1 -1);
至善者善之敌 2011-07-11
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 wuzhi11love 的回复:]
引用 1 楼 c_losed 的回复:

木有结束符C/C++ code

char tmp_content[50] = {0};

乱码的问题解决了,可是怎么输入www.renren.com呢?我上面的方法输出的总是有Host:
[/Quote]
定义一个临时空间,拷贝你想要的内容,去掉Host:就可以了
wuzhi11love 2011-07-11
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 c_losed 的回复:]

木有结束符C/C++ code

char tmp_content[50] = {0};
[/Quote]
乱码的问题解决了,可是怎么输入www.renren.com呢?我上面的方法输出的总是有Host:
风吹PP凉SS 2011-07-11
  • 打赏
  • 举报
回复
我的MFC程序也经常出现“烫烫烫”
afreet2006 2011-07-11
  • 打赏
  • 举报
回复
应该判断 pos2 - pos1 < (50 -1)
然后添加结束符
tmp_content[pos2-pos1 - 1] = '\0';
ff007bit 2011-07-11
  • 打赏
  • 举报
回复
加一个结束符吧,楼上说得很清楚了
至善者善之敌 2011-07-11
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 c_losed 的回复:]
木有结束符C/C++ code

char tmp_content[50] = {0};
[/Quote]

恩,读到了未初始化的内存空间
帅得不敢出门 2011-07-11
  • 打赏
  • 举报
回复

char *tmpCh="Host: www.renren.com demonbug=&email=15951983657&password=19921231&origURL=http%3A%2F %2Fwww.renren.com%2Fhome&domain=renren.com";
char tmp_content[50];
char *pos1=NULL;
char *pos2=NULL;

pos1=strstr(tmpCh, "Host:");
pos1=pos1+strlen("Host:");
pos2=strstr(tmpCh, "demonbug");
strncpy(tmp_content, pos1 ,pos2-pos1);
tmp_content[pos2-pos1] = '\0';
printf("%s", tmp_content);

bdmh 2011-07-11
  • 打赏
  • 举报
回复
看看tmp_content中的内容,为内容后的一个字符,写入结束符,否则不知道哪里结束
c_losed 2011-07-11
  • 打赏
  • 举报
回复
木有结束符

char tmp_content[50] = {0};
Build 1632
requires software maintenance through 2008.04.03. (Beta release.)
New! Added context-sensitive help to VA X dialogs. Click ? or press F1 to get help. (case=8980)
New! Visual Studio 2008-style transparent listboxes are available in all IDEs. Hold down Ctrl when listbox is displayed to activate. (case=10072) 7209, 6972
New! Added option to include or exclude refactoring suggestions in listboxes; see Advanced | Refactoring | Include refactoring suggestions in listboxes. (case=10428) 5797, 7254
"return" takes precedence over "RETCODE" in suggestion lists. (case=11277) 7036
Fixed incompatibility with XNA Game Studio 2.0. (case=10703) 7064
Restored "put n spaces between method name and ()" option under Advanced | Corrections. (case=10995) 7304
Fixed a problem typing "else" on a line by itself. (case=8415)
Debugger tooltips display without flickering. (case=8817) 6647
Fixed hang when opening web site project in Visual Studio 2008. (case=10401)
Fixed intermittent crash when typing a VB Imports statement in Visual Studio 2008 on Windows Vista. (case=15154)
Ctrl+Tab document switching is handled properly in Visual Studio 2008. (case=10303) 7010
Visual Studio 2008 C++ include directories that contain double backslashes due to environment variable expansion are located and parsed correctly. (case=11261)
Highlight current line works properly in .js and .asp/.aspx files in Visual Studio 2008. (case=15384)
Visual Basic enumerations are parsed correctly. (case=12161)
Removed C-style comment and semicolon from Encapsulate Field in Visual Basic files. (case=11160, case=4475) 7107
Object methods called on boxed string literals in C# are parsed correctly. (case=8012) 6513
Subsequent rename operations issued from VA Outline target the correct symbol. (case=10502) 7039
MFC dispatch map is shown in VA Outline. (case=10514)
Tooltips are positioned correctly when VA Outline is undocked in VC6. (case=9976) 6946
VA Outline shows correct hierarchy for C++ classes containing friend methods without friend class declaration. (case=10740) 7072
.Net symbols are excluded from suggestion lists in unmanaged C++ solutions. (case=11391) 7148
Fixed Extract Method with for each loop in managed C++. (case=14864) 7348
Typing a dot after a C++ constructor invocation [ e.g. std::string("some text"). ] displays member list properly. (case=9876)
C++ using declarations (using namespace::identifier) are parsed correctly. (case=9436)
STL list<> and vector<> member lists appear correctly following a "using namespace std::list" or "using namespace std::vector" directive. (case=12345) 7226
Empty C++ preprocessor directives are ignored (fixes problem parsing Boost library). (case=10353)
Typedefs declared inside template classes are parsed correctly. (case=12098)
Improved parsing of STL iterator patterns (case=11842) 7136, 7202, 7212
Improved stability when parsing deep templates. (case=15454)
Fixed dereferenced iterators missing from Find References / Rename. (case=1702) 6451, 4978
Cloned Find References windows are not hidden behind the VC6 IDE. (case=10201) 7000, 7026
IDE warning message about writing to a read-only file is brought to the foreground during a rename operation if applicable. (case=8958)
#include paths are preserved when typing a slash with Repair Case disabled. (case=12025) 7200
C# generic methods are colored properly. (case=9300) 6801
Comments in tooltips and views use IDE comment color. (case=9363) 6904, 6808
Dialog edit controls are colored properly in Windows Vista. (case=9281)
Filenames displayed in lists and views are not syntax colored. (case=12556, case=12788)
Foreground text color is automatically changed if it matches the background color. (case=14268)
VA View Symbols in Solution list items are colored properly. (case=14899)
Quick Info and Parameter Tooltips invoked via the keyboard are colored properly. (case=3082) 5462
Goto (Alt+G) handles template class typedefs. (case=4249) 6168, 5774
Goto handles duplicate files better (as with VSS shared directories). (case=5567, case=7457) 6027, 6021
Listboxes are positioned such that they are not truncated at the right edge of the screen. (case=5178)
Listbox remains on the same side of a symbol (either above or below) when typing inside parentheses. (case=8998) 6672
Windows Vista visual styles are applied to listboxes. (case=9275)
Accepting a suggestion from a listbox properly replaces acronym text. (case=14290) 7316
Fixed disappearing listboxes in .js and .asax files. (case=1699, case=15295) 4843
Fixed bad icons appearing in suggestion lists. (case=14469)
#include directives listed in Find References results are displayed with question mark icons. (case=9592) 6869
Esc key turns off Highlight All when Find References results window is undocked. (case=9364) 6803
Find References error messages may optionally be displayed in the status bar instead of a modal message box. (case=10226) 7038, 6997
Spelling errors in comments with XML tags are underlined. (case=9649) 6893
XML comment suggestion list opened with < functions properly. (case=12324) 7229
Suggestions are suppressed in comments and string literals. (case=10480) 5797, 7030, 7055
Change Signature does not cause some known symbols to become unknown. (case=10432) 6762
"Enable automatic Quick Info Tooltips" option is forced on when enabling "Display comments from source files when available" option in Advanced | Display. (case=10967)
Macros in [VA X install directory]\Misc\stdafx.h are parsed each time a project is opened. (case=284)
Surround with { indents properly when selection is made from bottom to top. (case=1521) 6792, 5961, 5796, 5249
Long words (>64 chars) in comments are not underlined as mistyped. (case=3485) 5634, 5588
Improved Autosave performance. (case=9821) 6916, 5613
Open File in Solution grid lines are drawn correctly in Windows XP. (case=9948)
Forward-declared stable symbols are shown in italic. (case=399) 2263, 1934, 1912
Repair Case changes only those symbols that differ by case alone (similarly named symbols are not changed). (case=8723)
Corrected spacing around spell check replacements. (case=7768) 6471
Eliminated spurious suggestions. (case=12061) 6900
Source files residing in directories named p4win or p4v (or their descendants) are included when parsing. (case=11506) 7150
Missing VC6 toolbar icons have been restored (case=10126) 6980
Filtering toolbar shows the rightmost button correctly. (case=10623) 7044

文注释有乱码

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧