我正在尝试将int添加到多维char数组中。阅读下面的链接后,我想我可以使用sprintf。如果我不能使用sprintf,那么我可以采用另一种方式吗?
http://www.cplusplus.com/reference/cstdio/sprintf/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int main(int argc, char *argv[])
{
//{"TYPE", "ID", "SCOPE", "VALUE"}
char *symbol_table_variables[503][4] = {0};
int scope = 5;
int lower_bound_of_big_boy_counter = 0;
char scope_char[80] = {0};
sprintf (scope_char, "%d", scope);
printf("scope_char %s \n", scope_char);
symbol_table_variables[lower_bound_of_big_boy_counter][2] =
malloc(strlen(scope_char)+1);
strcpy(symbol_table_variables[lower_bound_of_big_boy_counter][2],
scope_char);
memset(scope_char, 0, 80);
//sprintf (symbol_table_variables[lower_bound_of_big_boy_counter][2], "%d", scope);
printf("symbol_table_variables[lower_bound_of_big_boy_counter][2] is %s \n",
symbol_table_variables[lower_bound_of_big_boy_counter][2]);
return 0;
}
更新。
Task IUserSecurityStampStore<T, string>.SetSecurityStampAsync(T user, string stamp)
{
var res = Utility.SetSecurityStamp(user, stamp); // needs to be called as Async
var identityUser = ToIdentityUser(res);
SetApplicationUser(user, identityUser);
return ??? ; // How do i get a task to return here ?
}
答案 0 :(得分:1)
symbol_table_variables[lower_bound_of_big_boy_counter][2]
没有为你调用未定义的行为分配内存。
一种解决方案是分配一些内存
symbol_table_variables[lower_bound_of_big_boy_counter][2] = malloc(32);
printf (symbol_table_variables[lower_bound_of_big_boy_counter][2], "%d", scope);
这并不是很好,因为你真的不知道你需要多少记忆。
我质疑是否需要2D数组字符串...