int my_strcmp(const char *out, const char *in ){
for( ;*(in) , *(out) && *(in) == *(out); *out++,*in++ );
return *in <= *out ? *out > *in : -1 ;
}
I don't know why but it works )))
...
if (alignEntrySize & 1)
alignEntrySize++;
if (alignEntrySize & 2)
alignEntrySize += 2;
...
file = fopen(argv[1], "r");
if (file == NULL){}
exit(EXIT_FAILURE);
Those silly curly braces.
int t;
if ((t > 1) && (t < 2))
{
errorString = errorBuffer;
return -1;
}
int min(int a,int b,int c) //Function to return the minimum.
{
if(a < b)
{
if(a < c)return a;
else if(a > c)return c;
else return a;
}
else if(a > b)
{
if(b < c)return b;
else if(b > c)return c;
else return b;
}
else
{
if(a < c) return a;
else if(a > c) return c;
else return a;
}
}
This kind of things make me hate my work.
s[strlen(s)] = '\0';
int minimum(int a, int b, int c){
int mini =a*b*c;
int iterator=0;
int test[3];
test[0]=a;
test[1]=b;
test[2]=c;
for (iterator=0;iterator<3;iterator++){
if (test[iterator]<mini){
mini=test[iterator];
}
}
return mini;
}
I hope that your 3 numbers aren't larger than 1290!
if (argv[1][0]=='D'){
demo=1;
argv[1]++;
}
if (argv[1][0]=='P'){
if (sscanf(argv[1], "P%ux%ux%ux%ux%lfx%ux%u"
,&temporal_resample
,&input_w, &input_h, &rate, &input_gamma
,&output_w
,&output_h)!=7){
fprintf(stderr,"%s: Invalid argument format\n", progname);
print_usage();
exit(3);
}
ppm=1;
}else{
if (sscanf(argv[1], "%ux%ux%ux%ux%lfx%ux%u"
,&temporal_resample
,&input_w
,&input_h
,&rate
,&input_gamma
,&output_w
,&output_h)!=7){
fprintf(stderr,"%s: Invalid argument format\n", progname);
print_usage();
exit(3);
}
Found in a chroma subsampling algorithm.
void destroy_phone(T9obj* ptr_T9Obj){
free(ptr_T9Obj);
}
Such thoughtful name!
if (wiringPiMode == WPI_MODE_PINS)
pin = pinToGpio[pin];
else if (wiringPiMode == WPI_MODE_PHYS)
pin = physToGpio[pin];
else if (wiringPiMode != WPI_MODE_GPIO)
return;
the 3rd condition check throws you right off the train of logic.
int true = 0;
while (true)
{
//do something
}
true = false
double func_atof(char *p){
double integer = 0.0, div = 1.0 , fract = 0.0 , sign = 1.0;
if( *p == 45 ){sign = -1.0, *p++ ; }
while ( isdigit(*p) ) {
integer = ( *p++ ) + (10.0 * integer) - 48.0 ;
}
if(*p == 46 ){
(*p++ ) ;
while ( isdigit(*p) ) {
fract = ( *p++ ) + (10.0 * fract) - 48.0 ;
div *= 10;
}
}
return (integer + fract / div ) * sign ;
}
case ClientMessage:
if (*XGetAtomName(GLWin.dpy, event.xclient.message_type)
== *"WM_PROTOCOLS")
{ printf("Exiting sanely...\n");
done = True;
}
break;
someone just want to watch the world burn
// enum - full enumeration of knapsack solutions
// (C) Joshua Knowles
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
FILE *fp; // file pointer for reading the input files
int Capacity; // capacity of the knapsack (total weight that can be stored)
int Nitems; // number of items available
int *item_weights; // vector of item weights
int *item_values; // vector of item profits or values
int *temp_indexes; // list of temporary item indexes for sorting items by value/weight
int QUIET=0; // this can be set to 1 to suppress output
extern void read_knapsack_instance(char *filename);
extern void print_instance();
extern void sort_by_ratio();
extern int check_evaluate_and_print_sol(int *sol, int *total_value, int *total_weight);
void enumerate();
int next_binary(int *str, int Nitems);
int main(int argc, char *argv[])
{
read_knapsack_instance(argv[1]);
print_instance();
enumerate();
return(0);
}
void enumerate()
{
// Do an exhaustive search (aka enumeration) of all possible ways to pack
// the knapsack.
// This is achieved by creating every binary solution vector of length Nitems.
// For each solution vector, its value and weight is calculated.
int i; // item index
int solution[Nitems+1]; // (binary) solution vector representing items packed
int best_solution[Nitems+1]; // (binary) solution vector for best solution found
int best_value; // total value packed in the best solution
double j=0;
int total_value, total_weight; // total value and total weight of current knapsack solution
int infeasible; // 0 means feasible; -1 means infeasible (violates the capacity constraint)
// set the knapsack initially empty
for(i=1;i<=Nitems;i++)
{
solution[i]=0;
}
QUIET=1;
best_value=0;
while(!(next_binary(&solution[1], Nitems)))
{
/* ADD CODE IN HERE TO KEEP TRACK OF FRACTION OF ENUMERATION DONE */
// calculates the value and weight and feasibility:
infeasible=check_evaluate_and_print_sol(solution, &total_value, &total_weight);
/* ADD CODE IN HERE TO KEEP TRACK OF BEST SOLUTION FOUND*/
}
/* ADD CODE TO PRINT OUT BEST SOLUTION */
}
int next_binary(int *str, int Nitems)
{
// Called with a binary string of length Nitems, this
// function adds "1" to the string, e.g. 0001 would turn to 0010.
// If the string overflows, then the function returns 1, else it returns 0.
int i=Nitems-1;
while(i>=0)
{
if(str[i]==1)
{
str[i]=0;
i--;
}
else
{
str[i]=1;
break;
}
}
if(i==-1)
{
return(1);
}
else
{
return(0);
}
}
A genuine UoM lab.
strcpy(szBuffer, sBuffer);
so many questions given you by Hungarian notation