App-Cheats
view release on metacpan or search on metacpan
int main(int argc, char *argv[]){
int i;
for(i=0; i<argc; i++){
printf("argv[%d]: %s\n", argc, argv[i]);
}
return(0);
}
# Get ascii and characters in c code (DES)
printf("d:%d c:%c\n", 'A', 'A');
# Rename the oms trace files
ls -1 | perl -lpe '$o=$_; s/_[c0][a-z0-9]*_\d+//; rename $o => $_'
# Call C++/CPP function from C Step 1(OMS)
# Put code inside:
#ifdef __cplusplus
# // c++ code goes here
#endif
# Call C++/CPP function from C Step 2(OMS)
# Make external the function
extern "C" void my_func(void);
# Macro function in c code (OMS,bison,flex)
#define DEBUG 1
#define PRINT_IN_DEBUG(token) if(DEBUG){ cout << " Flex saw [" << yytext << "] (" << token << ")" << endl; }
# Use value from a string.
# Convert "std:string" to "const char *"
std::string name
name.c_str()
# Convert "std:string" to "char *"
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:
( run in 2.437 seconds using v1.01-cache-2.11-cpan-e93a5daba3e )