I have a code that is executable without error messages but it seems like it denies to run the code
I call by the "spawnl" command. This is my code and I receive "error=-1". I tried may different ways to solve the situation but I always receive the "-1" for an answer. I use Dev C++ compiler with 32bit release. My problem is to call the other program, sending the name of the file.
#include <stdlib.h>
#include <graphics.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <conio.h>
#include <process.h>
#include <ctype.h>
#include <dir.h>
#include <windows.h>
#include <dos.h>
#include <iostream>
#include <stddef.h>
void translate_to_ascii_files(),
save_mesh_data(),
make_no(),
give_names();
int load_patches(char *);
FILE *memco ;
int outnod[400] ;
float r_vector[21][21][3],cx[500],cy[500],cz[500] ;
int NOP1,NOP2; /* Number Of Points */
int patches;
char nams[26][26];
int num_of_files;
int kk,nv,nh,exnod,totnod ;
int no[4][400];
char filename[26];
void *buf;
COORD coord= {0,0};
HANDLE hConsole;
using namespace std; // std::cout, std::cin
void gotoxy(int x,int y) {
coord.X=x;
coord.Y=y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
}
int main(int argc,char *argv[]) {
char com_nam[26];
int counter1,counter2,i;
int error;
system("cls");
give_names();
printf("give the final filename:");scanf("%s",filename);
for(patches=1;patches<=num_of_files;patches++) {
strcpy(com_nam,nams[patches]);
load_patches(com_nam); /* load patches for meshing*/
i=1;
for(counter1=0;counter1<=NOP1;counter1++) {
for(counter2=0;counter2<=NOP2;counter2++) {
cx[i]=r_vector[counter1][counter2][0];
cy[i]=r_vector[counter1][counter2][1];
cz[i]=r_vector[counter1][counter2][2];
i=i+1;
}
}
nh=NOP1+1;nv=NOP2+1;
make_no();
save_mesh_data();
if(argc ==1){
error=spawnl(P_WAIT,"c:\\cpprog\\unitsrf.exe","",filename,NULL);
if (error ==0) {
else {printf ("error=%d\n",error); system("PAUSE");
} }
else{gotoxy(2,11);printf("error=%s\n\n",argv[1]);
system("PAUSE");
}
} translate_to_ascii_files();
}
Related
I write a simple c++ code. In my code, I create two threads, then I name the two threads TCPCall30003Proc and TCPCall30004Proc, but I can not find them using top command with option -H. My os is ubuntu 18.
#include <pthread.h>
#include <thread>
#include <stdio.h>
#include <time.h>
#include <iostream>
#include <stdlib.h>
#include <chrono>
#include <unistd.h>
void f1(int num)
{
printf("1\n");
while(1)
{
sleep(1);
}
}
void f2(int num)
{
printf("2\n");
while(1)
{
sleep(1);
}
}
int main(int argc, char **argv)
{
std::thread thd_1 = std::thread(f1, 1);
std::thread thd_2 = std::thread(f2, 1);
pthread_setname_np(thd_1.native_handle(), "TCPCall30003Proc");
pthread_setname_np(thd_2.native_handle(), "TCPCall30004Proc");
while(1)
{
sleep(1);
}
return 0;
}
From the pthread_setname_np manual page:
The thread name is a meaningful C language string, whose length is restricted to 16 characters, including the terminating null byte ('\0').
[Emphasis mine]
You names are 17 characters, including the null-terminator.
If you check what pthread_setname_np returns it should return -1 and with errno set to ERANGE.
You need to shorten your names.
#include <graphics.h>
#include <conio.h>
#include <iostream>
using namespace std;
int main(){
int gd = DETECT,gm;
/* warning deprecated convesion from string to char* [wWrite-strings] */
initgraph(&gd,&gm, "C:\\TURBOC3\\BGI");
circle(300,300,50);
closegraph();
getch();
return 0;
}
Store the string in a modifiable array:
char bgi[] = "C:\\TURBOC3\\BGI";
initgraph(&gd,&gm,bgi);
I wrote this code:
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <iterator>
#include <vector>
#include <regex>
using namespace std;
int compile()
{
string linecode;
linecode = "_hello:";
if (std::regex_match (linecode, std::regex("(_)(.*)(:)") ))
{
cout<<"...";
}
else if (std::regex_match (linecode, std::regex("(#)(.*)(:)") ))
{
cout<<"###";
}
return 1;
}
int main(int argc, char** argv)
{
compile();
return 0;
}
And i get this error:
enter image description here
cstring error, probably in regex library.
How i can fix this ?
Thanks in advance.
int calculate (int a , int b)
{
return a+b;
}
int main ()
{
return 0 ;
}
as you know EnumSystemLocales and EnumLocalesProc are two API for callback any function . I want to use these API but there is no any example in msdn or anywhere . here I want to callback the calculate function using these API .
Here is an example on how to use "EnumSystemLocales":
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
BOOL CALLBACK MyLocaleEnumProc(LPTSTR szLocaleString)
{
_tprintf(_T("%s\r\n"), szLocaleString);
return TRUE;
}
int _tmain()
{
EnumSystemLocales(&MyLocaleEnumProc, LCID_INSTALLED);
return 0;
}
If you just want to have a list of locales, you can do the following:
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <vector>
#include <string>
typedef std::vector<std::basic_string<TCHAR>> tLocales;
std::vector<std::basic_string<TCHAR>> g_locales;
BOOL CALLBACK MyLocaleEnumProc(LPTSTR szLocaleString)
{
g_locales.push_back(szLocaleString);
return TRUE;
}
int _tmain()
{
// Get all locales
EnumSystemLocales(&MyLocaleEnumProc, LCID_INSTALLED);
// Print out all locales
for(tLocales::const_iterator i=g_locales.begin(); i != g_locales.end(); i++)
{
_tprintf(_T("Locale: %s\r\n"), i->c_str());
}
return 0;
}
I am trying to learn how to make a modular program. So what I want to do is read an array of integers.
Main:
#include <stdio.h>
#include <stdlib.h>
#define NMAX 10
void read (int *n, int a[NMAX]);
int main()
{
int n, a[NMAX];
read(&n,a);
return 0;
}
Then I saved this file 'read.cpp':
#include <stdio.h>
#include <stdlib.h>
#define NMAX 10
void read (int *n, int a[NMAX])
{
int i;
printf("dati n:\n");
scanf("%d",n);
for (i=1;i<=*n;i++)
{
printf("a[%d]= ",i);
scanf("%d\n",&a[i]);
}
}
read.cpp compiles succesfully, but when I compile the main function I get the error "no reference to read".
Include read.cpp when compiling.
g++ -o out main.cpp read.cpp
or
add #include "read.cpp" in main program