App-Cheats
view release on metacpan or search on metacpan
std::string name
&name[0u]
# Read lines from a file (c program)
char *file_name = strcat(name, ".cmd");
char line[512];
FILE *fp;
fp = fopen(file_name, "r");
if(fp == NULL)
{
sendlog("ERROR: Could not open file: '%s'", file_name);
return 1;
}
while (fgets( line, sizeof(line), fp ) != NULL)
{
line[strlen(line) - 1] = '\0';
sendlog("Line1: '%s'", line);
yyParseAndExecute( line );
}
# The -m32 flag is necessary for both compiling and linking (gcc,DES)
# Sample C program. Prints to STDOUT and STDERR
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]){
fprintf(stderr, "Select folder:\n");
fprintf(stderr, "1 C:\\TOOLS\n");
fprintf(stderr, "2 C:\\BAT\n");
printf("C:\\TOOLS\n");
fprintf(stderr, "3 C:\\BAT2\n");
return 0;
}
# Fix Error: forbids converting a string constant to 'char*'
argv[1] = (char *) "name = bob";
#############################################################
## C,CPP - Options/Environmental Variables
#############################################################
# C,CPP - Options/Environmental Variables
C_INCLUDE_PATH - Additional directories to
search for C header files.
LIBRARY_PATH - Additional directories to
search for libraries during
linking.
LD_LIBRARY_PATH - Additional directories to
search for shared libraries
at runtime.
-I - Specify additional directories
to be searched for header
files during compilation.
-L - Specify additional directories
to be searched for libraries
during linking.
#############################################################
## C,CPP Asynchronous (Threads)
#############################################################
# Run a process/function async (thread)
# Add this to makefile
LIB += -pthread
#
# Add library
#include <pthread.h>
#
# Declare threads
pthread_t threads[1];
#
# Create threads and get return code
# Sending pattern as parameter (only one allowed)
# Thread ID is first parameter
int rc;
rc = pthread_create(&thread, NULL, send_thread, (void *) pattern );
pattern->tid = thread; // Save thread ID so we can later kill it (if needed)
if(rc) return; // Error
#
# Check return value
if(rc) sendlog("ERROR: return code from pthread_create() is %d", rc);
#
# Function is declared like this:
void *send_thread (void * args){
COMMAND_PATTERN* pattern = (COMMAND_PATTERN*) args; // Can use pattern normally
...
}
#
# Make sure to end the function with this:
# (it will exit the thread. don't use in main otherwise will get defunct/zombie process)
pthread_exit(NULL);
# Determine version and library used for threads
# NPTL - Native POSIX Threads Library # Threads share PID
# LinuxThreads # May be different PIDs (plus may other differences)
getconf GNU_LIBPTHREAD_VERSION # NPTL 2.7
#############################################################
## C,CPP - Debug
#############################################################
# Sleepy poll (debug,ddd,gdb,break)
# How to debug a progam
# Then after getting in using ddd, set wait_variable=0
int wait_variable = 1; while (wait_variable) sleep(1);
# Debug a UI program (DES,UI)
# Flags after --args are passed to the program
gdb progarm --args arg1 arg2
# Debug a c program given its pid (DES,UI)
gdb --pid 21620
gdb --pid `myps | grep snv | grep -v grep | awk '{print $4}'`
# gdb debugger navitation (commands,DES,UI)
(gdb) l[ist] # view code
(gdb) l[ist] main # view main code
(gdb) b[reak] main # Put a breakpoint at main()
( run in 0.833 second using v1.01-cache-2.11-cpan-2398b32b56e )