我需要在函数中传入char*并将其设置为cstring值.我可以在函数中将其正确设置为字符串,但它似乎在首先调用char*函数的函数中没有正确打印出来.
int l2_read(char *chunk,int length)
{
chunk = malloc( sizeof(char) * length);
int i;
for(i = 0; i < length; i++){
char c;
if(read(&c) < 0) return (-1); // this gets a single character
chunk[i] = c;
}
printf("%s",chunk); // this prints fine
return 1;
}
// main
char *string;
int value = l2_read(string,16);
printf("%s",chunk); // prints wrong
Run Code Online (Sandbox Code Playgroud) 我需要知道是否可以使用一些SQL语句在MYSQL中添加USER到ROLE ?
谢谢.
我正在开发一个Fortran应用程序,用于数值求解边界值问题的二阶ODE类型:-y''+ q(x)*y = r(x).在这个应用程序中,我使用高斯消除算法来求解线性方程组并将解决方案写入文件中.但对于解决方案向量,我收到了NaN.为什么会这样?这是一些代码.
subroutine gaussian_solve(s, c, error)
double precision, dimension(:,:), intent(in out) :: s
double precision, dimension(:), intent(in out) :: c
integer :: error
if(error == 0) then
call back_substitution(s, c)
end if
end subroutine gaussian_solve
!=========================================================================================
!================= Subroutine gaussian_ellimination ===============================
subroutine gaussion_ellimination(s, c, error)
double precision, dimension(:,:), intent(in out) :: s
double precision, dimension(:), intent(in out) :: c
integer, intent(out) :: error
real, dimension(size(s, 1)) :: temp_array
integer, dimension(1) :: ksave
integer :: i, j, k, n
real …Run Code Online (Sandbox Code Playgroud) 我的代码给了我段错误:我不明白,调试器说错误来自于从stored_打印值
char *stored_ = NULL;
char testMessage[15];
//strcpy(stored_, testMessage);
for (int a = 0;a < 10; a++)
{
sprintf(testMessage,"Message::%i\n",a);
printf("string is:%s;length is %i\n",testMessage,strlen(testMessage));
stored_ = (char*) realloc (stored_, sizeof(char) * (strlen(testMessage) * (a+1) ));
strcpy(&stored_[a], testMessage);
}
for (int b = 0;b < 10; b++)
{
printf("inside:|%s|\n",stored_[b]);
}
Run Code Online (Sandbox Code Playgroud) STARTUPINFO si;
PROCESS_INFORMATION pi;
memset(&si, 0, sizeof(si));
memset(&pi, 0, sizeof(pi));
si.cb = sizeof(si);
LPCWSTR procName =(LPCWSTR)"D:\\test dir 1\\Calc.exe";
LPWSTR procArg =(LPWSTR)"blacknull";
if(CreateProcess(procName,procArg,0,0,0,CREATE_DEFAULT_ERROR_MODE,0,0,&si,&pi))
{
//do some work
}
printf( "CreateProcess failed (%d).\n", GetLastError());
system("Pause");
Run Code Online (Sandbox Code Playgroud)
它不断抛出错误(2) - > The System cannot find the file specified.
我不知道出了什么问题.我也尝试在同一个Dir中使用"Calc.exe".但它不起作用.
我在远程计算机上运行SQL Server 2008.我们说这台机器叫做XYZ.以下作品:
运行以下命令:
USE SampleDB
GO
CREATE TABLE [dbo].[SampleData](
[ColA] [varchar](50) NULL,
[ColB] [varchar](500) NULL
) ON [PRIMARY]
GO
BULK INSERT [dbo].[SampleData]
FROM "H:\Scratch\OUTPUT_Sample"
WITH
(
FIELDTERMINATOR = '$',
ROWTERMINATOR = '\n',
FIRSTROW = 2
)
GO
Run Code Online (Sandbox Code Playgroud)这完全没问题.现在,我通过执行以下操作连接到另一个SQL Server ABC:
我收到以下错误:
Msg 4861, Level 16, State 1, Line 2
Cannot bulk load because the file "H:\Scratch\OUTPUT_Scratch" could not be opened. Operating system error code 3(The system cannot find the path specified.).
Run Code Online (Sandbox Code Playgroud)
有人能告诉我如何解决这个问题吗?我想我需要为某个帐户提供一些权限,但我不知道如何找到这个,也不知道给予该帐户的权限.我使用时 …
我正在尝试查看正在读取的字符串的结尾是否为".如果不是,我希望它打印出来的东西.
if(!line.find_last_of("\"")) {
cout << "Extra parameter is typed.";
continue;
Run Code Online (Sandbox Code Playgroud)
我试图使用find_last_of但是当我运行它时,无论命令是否有额外的参数,都会打印额外的参数.例:
lc "file.txt" -suppose to true so it's suppose to continue program but returns false
lc "file.txt" lk - suppose to return false and it does but should only return false for this type of case.
Run Code Online (Sandbox Code Playgroud) 我具有抽象用C实现的串行和套接字IO(Linux / Windows)的功能。所有这些都被标记为,extern "C"因为它们也可以从C ++中调用。
在这里使用__attribute__((__nothrow__))(或MinGW Macro __MINGW_NOTHROW)是否安全?我可以假设没有抛出异常吗?
调用的函数-套接字:(未列出WinSock的所有新增功能
)
socketconnectsend / recvclose(closesocket在Windows上)sendto / recvfrom所谓的函数-串行:
由于Windows / Linux之间的串行IO代码差异很大,因此此处未列出所有代码
opentcgetattrread / writecloseCreateFileGetCommState / SetCommTimeoutsReadFile / WriteFileCloseHandle由于ANSI C没有例外(如果我错了,请纠正我),它们不会被抛出,但是GCC扩展和OS API调用又如何呢?
文档:http : //gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html(请参阅参考资料nothrow)。
当我运行下面的代码时,我得到错误:第14行和第26行的数组分配无效.我相当新(1周)到c ++所以我有点困惑.我搜索过,找不到解决问题的答案.
#include <iostream>
int main()
{
using namespace std;
char usrname[5];
char psswrd[9];
cout << "Please enter your username:";
cin >> usrname;
if (usrname = "User")
{
cout << "Username correct!";
}
else
{
cout << "Username incorrect!";
}
cout << "Please enter your password:";
cin >> psswrd;
if (psswrd = "password")
{
cout << "The password is correct! Access granted.";
}
else
{
cout << "The password is incorrect! Access denied.";
}
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我是一名初学者,在大学学习C语言,并且想知道为什么这段代码总是产生一个随机数,而不是像我期望的那样.
码:
#include<stdio.h>
int main(void){
double a, b = 32.5;
a = 2 / 5 * (b - 30);
printf("%d\n", a);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当我运行代码时,它每次打印出一个不同的随机值:
-780835368
-1509625304
1267593528
Run Code Online (Sandbox Code Playgroud)
是我得到的一些结果.任何帮助表示赞赏.