Search Results

Search found 1848 results on 74 pages for 'printf'.

Page 22/74 | < Previous Page | 18 19 20 21 22 23 24 25 26 27 28 29  | Next Page >

  • Howto access thread data outside a thread

    - by Quandary
    Question: I start the MS Text-to-speech engine in a thread, in order to avoid a crash on DLL_attach. It starts fine, and the text to speech engine gets initialized, but I can't access ISpVoice outside the thread. How can I access ISpVoice outside the thread ? It's a global variable after all... #include <windows.h> #include <sapi.h> #include "XPThreads.h" ISpVoice * pVoice = NULL; unsigned long init_engine_thread(void* param) { Sleep(5000); printf("lolthread\n"); //HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED); HRESULT hr = CoInitialize(NULL); if(FAILED(hr) ) { MessageBox(NULL, TEXT("Failed To Initialize"), TEXT("Error"), 0); char buffer[2000] ; sprintf(buffer, "An error occured: 0x%08X.\n", hr); FILE * pFile = fopen ( "c:\\temp\\CoInitialize_dll.txt" , "w" ); fwrite (buffer , 1 , strlen(buffer) , pFile ); fclose (pFile); } else { printf("trying to create instance.\n"); //HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **) &pVoice); //hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **) &pVoice); //HRESULT hr = CoCreateInstance(__uuidof(ISpVoice), NULL, CLSCTX_INPROC_SERVER, IID_ISpVoice, (void **) &pVoice); HRESULT hr = CoCreateInstance(__uuidof(SpVoice), NULL, CLSCTX_ALL, IID_ISpVoice, (void **) &pVoice); if( SUCCEEDED( hr ) ) { printf("Succeeded\n"); hr = pVoice->Speak(L"The text to speech engine has been successfully initialized.", 0, NULL); } else { printf("failed\n"); MessageBox(NULL, TEXT("Failed To Create COM instance"), TEXT("Error"), 0); char buffer[2000] ; sprintf(buffer, "An error occured: 0x%08X.\n", hr); FILE * pFile = fopen ( "c:\\temp\\CoCreateInstance_dll.txt" , "w" ); fwrite (buffer , 1 , strlen(buffer) , pFile ); fclose (pFile); } } if(pVoice != NULL) { pVoice->Release(); pVoice = NULL; } CoUninitialize(); return NULL; } XPThreads* ptrThread = new XPThreads(init_engine_thread); BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: //init_engine(); LoadLibrary(TEXT("ole32.dll")); ptrThread->Run(); break; case DLL_THREAD_ATTACH: break; case DLL_THREAD_DETACH: break; case DLL_PROCESS_DETACH: break; } return TRUE; }

    Read the article

  • Problem on a Floyd-Warshall implementation using c++

    - by Henrique
    I've got a assignment for my college, already implemented Dijkstra and Bellman-Ford sucessfully, but i'm on trouble on this one. Everything looks fine, but it's not giving me the correct answer. Here's the code: void FloydWarshall() { //Also assume that n is the number of vertices and edgeCost(i,i) = 0 int path[500][500]; /* A 2-dimensional matrix. At each step in the algorithm, path[i][j] is the shortest path from i to j using intermediate vertices (1..k-1). Each path[i][j] is initialized to edgeCost(i,j) or infinity if there is no edge between i and j. */ for(int i = 0 ; i <= nvertices ; i++) for(int j = 0 ; j <= nvertices ; j++) path[i][j] = INFINITY; for(int j = 0 ; j < narestas ; j++) //narestas = number of edges { path[arestas[j]->v1][arestas[j]->v2] = arestas[j]->peso; //peso = weight of the edge (aresta = edge) path[arestas[j]->v2][arestas[j]->v1] = arestas[j]->peso; } for(int i = 0 ; i <= nvertices ; i++) //path(i, i) = 0 path[i][i] = 0; //test print, it's working fine //printf("\n\n\nResultado FloydWarshall:\n"); //for(int i = 1 ; i <= nvertices ; i++) // printf("distancia ao vertice %d: %d\n", i, path[1][i]); //heres the problem, it messes up, and even a edge who costs 4, and the minimum is 4, it prints 2. //for k = 1 to n for(int k = 1 ; k <= nvertices ; k++) //for i = 1 to n for(int i = 1 ; i <= nvertices ; i++) //for j := 1 to n for(int j = 1 ; j <= nvertices ; j++) if(path[i][j] > path[i][k] + path[k][j]) path[i][j] = path[i][k] + path[k][j]; printf("\n\n\nResultado FloydWarshall:\n"); for(int i = 1 ; i <= nvertices ; i++) printf("distancia ao vertice %d: %d\n", i, path[1][i]); } im using this graph example i've made: 6 7 1 2 4 1 5 1 2 3 1 2 5 2 5 6 3 6 4 6 3 4 2 means we have 6 vertices (1 to 6), and 7 edges (1,2) with weight 4... etc.. If anyone need more info, i'm up to giving it, just tired of looking at this code and not finding an error.

    Read the article

  • [C] glist.c: No such file or directory

    - by sterh
    Hello, I have c/gtk+ application and GList which filled three elements, when i try to run following code with gdb: if (g_list_length(mw->img_list) > 0) printf(">0"); else printf("<0"); i see: Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 0xb73c4700 (LWP 7936)] IA__g_list_length (list=0x6e6920) at glist.c:767 767 glist.c: No such file or directory. in glist.c What is it? Thank you.

    Read the article

  • Help with bugs in a C code

    - by Yanki Twizzy
    This C code is giving me some unpredictable results. The program is meant to collect 6 nos and print out the max, position of the max no and the average. It's supposed to have only 3 functions - input, max_avr_pos and output for doing what the code is supposed to do but I am getting unpredictable results. Please what could be the problem #include <stdio.h> #include <stdlib.h> #include <conio.h> void input_vals(int arrnum[]); void max_ave_val(int arrnum1[],double *average,int *maxval,int *position); void print_output(double *average1,int *maxval1,int *position1); int main(void) { int arrnum[6],maxval2,position2; double average2; input_vals(arrnum); max_ave_val(arrnum,&average2,&maxval2,&position2); print_output(&average2,&maxval2,&position2); _getche(); return 0; } void input_vals(int arrnum[]) { int count; printf("\n Please enter six numbers\n"); for(count=0;count<6;count++) { scanf("%d",&arrnum[count]); } } void max_ave_val(int arrnum1[],double *average,int *maxval,int *position) { int total=0; int cnt,cnt1,cnt2,limit,maxval2,post; limit=6; /* finding the max value*/ for(cnt=0;cnt<limit-1;cnt++) for(cnt1=limit-1;cnt1>cnt;--cnt1) { if(arrnum1[cnt1-1]>arrnum1[cnt1]) { maxval2=arrnum1[cnt-1]; post=(cnt-1)+1; } else { maxval2=arrnum1[cnt1]; post=cnt1+1; } } *maxval=maxval2; *position=post; /* solving for total */ for(cnt2=0;cnt2<limit;cnt2++); { total=total+arrnum1[cnt2]; } *average=total/limit; } void print_output(double *average1,int *maxval1,int *position1) { printf("\n value of the highest of the numbers is %d\n",*maxval1); printf("\n the average of all the numbers is %g\n",*average1); printf("\n the postion of the highest number in the list is %d\n",*position1); }

    Read the article

  • segmentation fault for the simplest program??

    - by capex
    Hi, I am just starting out, but this piece of code is giving me a 'segmentation fault' and I can't find out what's wrong with it: #include<stdio.h> int main (void) { int number = 0; int lastDigit = 0; printf("Enter an integer: "); scanf("%d", number); number = number*10; printf("Number times ten is %d.\n", number); return 0; }

    Read the article

  • Format stdin in bash

    - by User1
    I have a multi-line string coming from another program that I want to convert to a SQL command. I was hoping that printf could help me, but it doesn't seem to work: echo -e '1\n2\n3'|printf 'SELECT %s INTO MyTable' I was hoping to see: SELECT '1 2 3' INTO MyTable But I got: SELECT INTO MyTable How can I get the %s to read stdin?

    Read the article

  • post and pre increment in c

    - by jammkie same
    void main() { int a=2 , c; c=a++ + ++a + ++a + ++a; printf("%d",c); } prints 20, whereas void main() { int a=2; int c=a++ + ++a + ++a + ++a; printf("%d",c); } prints 17. Can someone explain the reason for this.

    Read the article

  • C Language - \n - creating virus

    - by sagar
    #include<stdio.h> #include<conio.h> union abc { int a; int x; float g; }; struct pqr { int a; int x; float g; } ; void main() { union abc b; struct pqr c; clrscr(); b.a=10; textbackground(2); textcolor(6); cprintf(" A = %d",b.a); printf("\nUnion = %d",sizeof(b)); printf("\nStructure = %d",sizeof(c)); getch(); } Now, Save this program as virus.cpp ( or any name that you like ) I am using Turbo C comiler to complie this program & run from trubo c. ( Ctrl + F9 ) I don't know weather to ask this question at stack over flow or at super user. I am using Windows 7 & I have installed Avira AntiVir virus system. I am not here for any kind of advertisement of microsoft or antivirus system. I am just here for solution of my query. When I tried to run above program - It creates a worm (DOS/Candy). I believe there is nothing wrong in program. Oke.. Now here is something special. Execute the same program with following difference. Here the only difference is space between \n #include<stdio.h> #include<conio.h> union abc { int a; int x; float g; }; struct pqr { int a; int x; float g; } ; void main() { union abc b; struct pqr c; clrscr(); b.a=10; textbackground(2); textcolor(6); cprintf(" A = %d",b.a); printf("\n Union = %d",sizeof(b)); printf("\n Structure = %d",sizeof(c)); getch(); } The difference is only \n and space. Question is "Why my simple program is detected as virus?? " Thanks in advance for sharing your knowledge. Sagar.

    Read the article

  • multi-thread access MySQL error

    - by user188916
    I have written a simple multi-threaded C program to access MySQL,it works fine except when i add usleep() or sleep() function in each thread function. i created two pthreads in the main method, int main(){ mysql_library_init(0,NULL,NULL); printf("Hello world!\n"); init_pool(&p,100); pthread_t producer; pthread_t consumer_1; pthread_t consumer_2; pthread_create(&producer,NULL,produce_fun,NULL); pthread_create(&consumer_1,NULL,consume_fun,NULL); pthread_create(&consumer_2,NULL,consume_fun,NULL); mysql_library_end(); } void * produce_fun(void *arg){ pthread_detach(pthread_self()); //procedure while(1){ usleep(500000); printf("producer...\n"); produce(&p,cnt++); } pthread_exit(NULL); } void * consume_fun(void *arg){ pthread_detach(pthread_self()); MYSQL db; MYSQL *ptr_db=mysql_init(&db); mysql_real_connect(); //procedure while(1){ usleep(1000000); printf("consumer..."); int item=consume(&p); addRecord_d(ptr_db,"test",item); } mysql_thread_end(); pthread_exit(NULL); } void addRecord_d(MYSQL *ptr_db,const char *t_name,int item){ char query_buffer[100]; sprintf(query_buffer,"insert into %s values(0,%d)",t_name,item); //pthread_mutex_lock(&db_t_lock); int ret=mysql_query(ptr_db,query_buffer); if(ret){ fprintf(stderr,"%s%s\n","cannot add record to ",t_name); return; } unsigned long long update_id=mysql_insert_id(ptr_db); // pthread_mutex_unlock(&db_t_lock); printf("add record (%llu,%d) ok.",update_id,item); } the program output errors like: [Thread debugging using libthread_db enabled] [New Thread 0xb7ae3b70 (LWP 7712)] Hello world! [New Thread 0xb72d6b70 (LWP 7713)] [New Thread 0xb6ad5b70 (LWP 7714)] [New Thread 0xb62d4b70 (LWP 7715)] [Thread 0xb7ae3b70 (LWP 7712) exited] producer... producer... consumer...consumer...add record (31441,0) ok.add record (31442,1) ok.producer... producer... consumer...consumer...add record (31443,2) ok.add record (31444,3) ok.producer... producer... consumer...consumer...add record (31445,4) ok.add record (31446,5) ok.producer... producer... consumer...consumer...add record (31447,6) ok.add record (31448,7) ok.producer... Error in my_thread_global_end(): 2 threads didn't exit [Thread 0xb72d6b70 (LWP 7713) exited] [Thread 0xb6ad5b70 (LWP 7714) exited] [Thread 0xb62d4b70 (LWP 7715) exited] Program exited normally. and when i add pthread_mutex_lock in function addRecord_d,the error still exists. So what exactly the problem is?

    Read the article

  • C: reading file and populating struct

    - by deostroll
    Hi, I have a structure with the following definition: typedef struct myStruct{ int a; char* c; int f; } OBJECT; I am able to populate this object and write it to a file. However I am not able to read the char* c value in it...while trying to read it, it gives me a segmentation fault error. Is there anything wrong with my code: //writensave.c #include "mystruct.h" #include <stdio.h> #include <string.h> #define p(x) printf(x) int main() { p("Creating file to write...\n"); FILE* file = fopen("struct.dat", "w"); if(file == NULL) { printf("Error opening file\n"); return -1; } p("creating structure\n"); OBJECT* myObj = (OBJECT*)malloc(sizeof(OBJECT)); myObj->a = 20; myObj->f = 45; myObj->c = (char*)calloc(30, sizeof(char)); strcpy(myObj->c, "This is a test"); p("Writing object to file...\n"); fwrite(myObj, sizeof(OBJECT), 1, file); p("Close file\n"); fclose(file); p("End of program\n"); return 0; } Here is how I am trying to read it: //readnprint.c #include "mystruct.h" #include <stdio.h> #define p(x) printf(x) int main() { FILE* file = fopen("struct.dat", "r"); char* buffer; buffer = (char*) malloc(sizeof(OBJECT)); if(file == NULL) { p("Error opening file"); return -1; } fread((void *)buffer, sizeof(OBJECT), 1, file); OBJECT* obj = (OBJECT*)buffer; printf("obj->a = %d\nobj->f = %d \nobj->c = %s", obj->a, obj->f, obj->c); fclose(file); return 0; }

    Read the article

  • How can c let a function declaration with any parameter type ?

    - by kamil çakir
    I forgot to write void parameter but it works the i put void it gives error it lets this: print(int size,int table[size][size]){ int i,j; printf("-------TABLE-------\n"); for(i = 0;i it says"previos implicit declaration was here " (means the call in main) void print(int size,int table[size][size]){ int i,j; printf("-------TABLE-------\n"); for(i = 0;i

    Read the article

  • How can c let a function declaration with any parameter type ?

    - by kamil çakir
    it lets this function declaration print(int size,int table[size][size]){ int i,j; printf("-------TABLE-------\n"); for(i = 0;i gives error in this situation 44 C:\Users.. previous implicit declaration of 'print' was here (print(size,table); call in main) void print(int size,int table[size][size]){ int i,j; printf("-------TABLE-------\n"); for(i = 0;i

    Read the article

  • best practice when referring to a program's name in C

    - by guest
    what is considered best practice when referring to a program's name? i've seen #define PROGRAM_NAME "myprog" printf("this is %s\n", PROGRAM_NAME); as well as printf("this is %s\n", argv[0]); i know, that the second approach will give me ./myprog rather than myprog when the program is not called from $PATH and that the first approach will guarantee consistence regarding the program's name. but is there anything else, that makes one approach superior to the other?

    Read the article

  • Why does DebugActiveProcessStop crash my debugging app?

    - by SparkyNZ
    I have a debugging program which I've written to attach to a process and create a crash dump file. That part works fine. The problem I have is that when the debugger program terminates, so does the program that it was debugging. I did some Googling and found the DebugActiveProcessStop() API call. This didn't show up in my older MSDN documentation as it was only introduced in Windows XP so I've tried loading it dynamicall from Kernel32.dll at runtime. Now my problem is that my debugger program crashes as soon as the _DebugActiveProcessStop() call is made. Can somebody please tell me what I'm doing wrong? typedef BOOL (*DEBUGACTIVEPROCESSSTOP)(DWORD); DEBUGACTIVEPROCESSSTOP _DebugActiveProcessStop; HMODULE hK32 = LoadLibrary( "kernel32.dll" ); if( hK32 ) _DebugActiveProcessStop = (DEBUGACTIVEPROCESSSTOP) GetProcAddress( hK32,"DebugActiveProcessStop" ); else { printf( "Can't load Kernel32.dll\n" ); return; } if( ! _DebugActiveProcessStop ) { printf( "Can't find DebugActiveProcessStop\n" ); return; } ... void DebugLoop( void ) { DEBUG_EVENT de; while( 1 ) { WaitForDebugEvent( &de, INFINITE ); switch( de.dwDebugEventCode ) { case CREATE_PROCESS_DEBUG_EVENT: hProcess = de.u.CreateProcessInfo.hProcess; break; case EXCEPTION_DEBUG_EVENT: // PDS: I want a crash dump immediately! dwProcessId = de.dwProcessId; dwThreadId = de.dwThreadId; WriteCrashDump( &de.u.Exception ); return; case CREATE_THREAD_DEBUG_EVENT: case OUTPUT_DEBUG_STRING_EVENT: case EXIT_THREAD_DEBUG_EVENT: case EXIT_PROCESS_DEBUG_EVENT : case LOAD_DLL_DEBUG_EVENT: case UNLOAD_DLL_DEBUG_EVENT: case RIP_EVENT: default: break; } ContinueDebugEvent( de.dwProcessId, de.dwThreadId, DBG_CONTINUE ); } } ... void main( void ) { ... BOOL bo = DebugActiveProcess( dwProcessId ); if( bo == 0 ) printf( "DebugActiveProcess failed, GetLastError: %u \n",GetLastError() ); hProcess = OpenProcess( PROCESS_ALL_ACCESS, TRUE, dwProcessId ); if( hProcess == NULL ) printf( "OpenProcess failed, GetLastError: %u \n",GetLastError() ); DebugLoop(); _DebugActiveProcessStop( dwProcessId ); CloseHandle( hProcess ); }

    Read the article

  • mysql timeout - c/C++

    - by user1262876
    Guys i'm facing a problem with this code, the problem is the timeout by timeout i mean the time it takes the program to tell me if the server is connected or not. If i use my localhost i get the answer fast, but when i connect to outside my localhost it takes 50sc - 1.5 min to response and the program frezz until it done. HOw can i fix the frezzing, or make my own timeout, like if still waiting after 50sc, tell me connection failed and stop? please use codes as help, becouse i would understand it better, thanks for any help i get PS: USING MAC #include "mysql.h" #include <stdio.h> #include <stdlib.h> // Other Linker Flags: -lmysqlclient -lm -lz // just going to input the general details and not the port numbers struct connection_details { char *server; char *user; char *password; char *database; }; MYSQL* mysql_connection_setup(struct connection_details mysql_details) { // first of all create a mysql instance and initialize the variables within MYSQL *connection = mysql_init(NULL); // connect to the database with the details attached. if (!mysql_real_connect(connection,mysql_details.server, mysql_details.user, mysql_details.password, mysql_details.database, 0, NULL, 0)) { printf("Conection error : %s\n", mysql_error(connection)); exit(1); } return connection; } MYSQL_RES* mysql_perform_query(MYSQL *connection, char *sql_query) { // send the query to the database if (mysql_query(connection, sql_query)) { printf("MySQL query error : %s\n", mysql_error(connection)); exit(1); } return mysql_use_result(connection); } int main() { MYSQL *conn; // the connection MYSQL_RES *res; // the results MYSQL_ROW row; // the results row (line by line) struct connection_details mysqlD; mysqlD.server = (char*)"Localhost"; // where the mysql database is mysqlD.user = (char*)"root"; // the root user of mysql mysqlD.password = (char*)"123456"; // the password of the root user in mysql mysqlD.database = (char*)"test"; // the databse to pick // connect to the mysql database conn = mysql_connection_setup(mysqlD); // assign the results return to the MYSQL_RES pointer res = mysql_perform_query(conn, (char*) "SELECT * FROM me"); printf("MySQL Tables in mysql database:\n"); while ((row = mysql_fetch_row(res)) !=NULL) printf("%s - %s\n", row[0], row[1], row[2]); // <-- Rows /* clean up the database result set */ mysql_free_result(res); /* clean up the database link */ mysql_close(conn); return 0; }

    Read the article

  • difference why.............

    - by gcc
    char x; for(i=0;i<256;i+=10) {x=i; if(x==i) printf("%d liii\n",i); else printf("%d sfffi\n",i); } 0 liii 10 liii 20 liii 30 liii 40 liii 50 liii 60 liii 70 liii 80 liii 90 liii 100 liii 110 liii 120 liii 130 sfffi 140 sfffi 150 sfffi 160 sfffi 170 sfffi 180 sfffi 190 sfffi 200 sfffi 210 sfffi 220 sfffi 230 sfffi 240 sfffi 250 sfffi

    Read the article

  • Get rid of Trailing Numbers in C

    - by Tech163
    For example, #include <stdio.h> int main (int argc, const char * argv[]) { char out = printf("teststring"); printf("%d\n", out); return 0; } will return teststring10. Anyone has an idea how to get rid of the 10? Thanks in advance.

    Read the article

  • Buffer Overrun Issues VC++

    - by sijith
    When i execute my code i am getting this error LPTSTR lpBuffer; ::GetLogicalDriveStrings(1024,lpBuffer); while(*lpBuffer != NULL) { printf("%s\n", lpBuffer); // or MessageBox(NULL, temp, "Test", 0); or whatever lpBuffer += lstrlen(lpBuffer)+1; printf("sizeof(lpBuffer) %d\n",lstrlen(lpBuffer)); } OutPut C sizeof(lpBuffer) 3 D sizeof(lpBuffer) 3 E sizeof(lpBuffer) 3 F sizeof(lpBuffer) 0

    Read the article

  • Can a process have two pid's?

    - by limp_chimp
    I'm studying computer systems and I've made this very simple function which uses fork() to create a child process. fork() returns a pid_t that is 0 if it's a child process. But calling the getpid() function within this child process returns a different, nonzero pid. In the code I have below, is newPid only meaningful in the context of the program, and not to the operating system? Is it possibly only a relative value, measured against the pid of the parent? #include <stdio.h> #include <unistd.h> #include <sys/types.h> #include <string.h> #include <errno.h> #include <stdlib.h> void unixError(char* msg) { printf("%s: %s\n", msg, strerror(errno)); exit(0); } pid_t Fork() { pid_t pid; if ((pid = fork()) < 0) unixError("Fork error"); return pid; } int main(int argc, const char * argv[]) { pid_t thisPid, parentPid, newPid; int count = 0; thisPid = getpid(); parentPid = getppid(); printf("thisPid = %d, parent pid = %d\n", thisPid, parentPid); if ((newPid = Fork()) == 0) { count++; printf("I am teh child. My pid is %d, my other pid is %d\n", getpid(), newPid); exit(0); } printf("I am the parent. My pid is %d\n", thisPid); return 0; } Output: thisPid = 30050, parent pid = 30049 I am the parent. My pid is 30050 I am teh child. My pid is 30052, my other pid is 0 Lastly, why is the child's pid 2 higher than the parent's, and not 1? The difference between the main function's pid and its parent is 1, but when we create a child it increments the pid by 2. Why is that?

    Read the article

  • Preprocessor #if directive

    - by Caslav
    I am writing a big code and I don't want it all to be in my main.c so I wrote a .inc file that has IF-ELSE statement with function and I was wondering can it be written like this: #if var==1 process(int a) { printf("Result is: %d",2*a); } #else process(int a) { printf("Result is: %d",10*a); } #endif I tried to compile it but it gives me errors or in best case it just goes on the first function process without checking the var variable (it is set to 0).

    Read the article

< Previous Page | 18 19 20 21 22 23 24 25 26 27 28 29  | Next Page >