← cproj

clean up

af166695700d39e16435d73fcbe003d637f6f9c1 · ovidiucs · Dec 17, 2019 20:47

+44 −600 · 8 files changed

  • graph/db/codevault/ret_array_from func.c +0 −24
  • graph/db/codevault/ret_multiple_values_from_func.c +0 −25
  • graph/db/pthreads/pthread_example.c +0 −38
  • graph/db/sqltest binary
  • graph/db/sqltest.c +0 −349
  • graph/db/sqltest.o binary
  • graph/db/sqltest2.c +0 −159
  • graph/ds/ds2.c +44 −5
diff --git a/graph/db/codevault/ret_array_from func.c b/graph/db/codevault/ret_array_from func.c
deleted file mode 100644
index 8237429..0000000
--- a/graph/db/codevault/ret_array_from func.c	
+++ /dev/null
@@ -1,24 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-
-int
-*getNextFive(int x) {
-  int *result = malloc(sizeof(int)*5);
-  int i;
-  for ( i=0;i<5;i++ ) {
-      result[i] = x+i+1;
-  }
-  return result;
-}
-
-int main (int argc, char** argv) {
-    int x = 5;
-
-    int *arr = getNextFive(x);
-      int i;
-      for ( i=0;i<5;i++ ) {
-      fprintf(stdout,"Value of arr is: %d\n", arr[i]);
-  }
-  free(arr);
-   return EXIT_SUCCESS;
-}
diff --git a/graph/db/codevault/ret_multiple_values_from_func.c b/graph/db/codevault/ret_multiple_values_from_func.c
deleted file mode 100644
index a1fa8fd..0000000
--- a/graph/db/codevault/ret_multiple_values_from_func.c
+++ /dev/null
@@ -1,25 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-
-int sumAndProduct(int a, int b, int* sum, int* prod){
-  if (sum == NULL || prod == NULL){
-    return(0);
-  }
-  *sum = a + b;
-  *prod = a * b;
-}
-
-
-int main (int argc, char** argv) {
-    int x = 5;
-    int y = 12;
-    int sum = 0;
-    int prod = 0;
-    int status = sumAndProduct(x, y, &sum, &prod);
-    if (!status) {
-      fprintf(stderr, "Something went wrong\n");
-    } else {
-    fprintf(stdout,"The sum is %d and the product is %d\n", sum, prod);
-    }
-   return EXIT_SUCCESS;
-}
diff --git a/graph/db/pthreads/pthread_example.c b/graph/db/pthreads/pthread_example.c
deleted file mode 100644
index 660cd94..0000000
--- a/graph/db/pthreads/pthread_example.c
+++ /dev/null
@@ -1,38 +0,0 @@
-#include <stdio.h>
-#include <unistd.h>
-#include <pthread.h>
-// https://youtu.be/uA8X5zNOGw8
-void *foo(void *arg){
-  int *iptr = (int *) arg;
-  for (int i = 0; i < 5; i++){
-  fprintf(stdout,"My Turn and %d %d\n", i, *iptr);
-  (*iptr)++;
-
-  sleep(1);
-
-  }
-  return NULL;
-}
-
-void bar(){
-  for (int i = 0; i < 2; i++){
-  fprintf(stdout,"Your Turn\n");
-  sleep(1);
-  }
-
-}
-int main (int argc, char** argv) {
-  int i = 5;
-  //1. Create thread.
-  pthread_t newthread;
-
-  //2. args, pthread_t address, NUL
-  pthread_create(&newthread, NULL,foo, &i);
-
-
-//  foo();
-   bar();
-  pthread_join(newthread,NULL);
-  fprintf(stdout,"Thread's done %d\n",i);
-   return 0;
-}
diff --git a/graph/db/sqltest b/graph/db/sqltest
deleted file mode 100755
index 76f5e1a..0000000
Binary files a/graph/db/sqltest and /dev/null differ
diff --git a/graph/db/sqltest.c b/graph/db/sqltest.c
deleted file mode 100644
index fed4a78..0000000
--- a/graph/db/sqltest.c
+++ /dev/null
@@ -1,349 +0,0 @@
-#include <stdio.h> // fprintf, printf
-#include <stdlib.h> // exit,
-#include <readline/readline.h> // readline
-#include <readline/history.h> //
-
-#include "../../include/sqlite3.h"
-//#include "./sqltest.h"
-  // Set a glbal string that will hold some SQL sample
-  // data
-
-#define DEBUG 0
-#define MEMWRITE 0
-
-  // sample test data
-char *sSql = "DROP TABLE IF EXISTS Friends;"
-	    "CREATE TABLE Friends(Id INTEGER PRIMARY KEY, Name TEXT, Age INTEGER);"
-	    "INSERT INTO Friends(Name,Age) VALUES ('Tom',10);"
-	    "INSERT INTO Friends(Name,Age) VALUES ('Rebecca',32);"
-	    "INSERT INTO Friends(Name,Age) VALUES ('Jim',34);"
-	    "INSERT INTO Friends(Name,Age) VALUES ('Roger',12);"
-	    "INSERT INTO Friends(Name,Age) VALUES ('Robert',16);";
-
-char *uSql = "UPDATE Friends SET Name = 'Jerry' WHRE id = 1;";
-// ---------------------------------FUNCTION DECLARATIONS--------------------------------------------
-
-int mainmenu(sqlite3 *db);
-int dbInsert(sqlite3 *db, char *data);
-int dbSelect(sqlite3 *db, char *data);
-int dbUpdate(sqlite3 *db, char *data);
-int setup(sqlite3 **db);
-static int callback(void *data, int argc, char **argv, char **azColName );
-
-// ---------------------------------START MAIN------------------------------------------------------
-
-int main(int argc, char **argv) {
-
-  // 1. Definitions
-  // Each opened SQLite database is represented by a pointer
-  // to an instance of the opaque structure named sqlite3
-  sqlite3 *db = NULL;
-
-  int rc;
-
-  // This string will hold the english language of the error description
-  char *zErrMsg;
-	  // 2. Get the return code from sqlite3_open
-
-
-
-  // Ensure that the proper arguments are given.````````
-  if (argc != 3 && argc != 1) {
-      fprintf(stderr, "Usage: %s DATABASE SQL-STATEMENT\n", argv[0]);
-      // Return error code
-      return 1;
-  } else if (argc == 3) {
-			rc = setup(&db);
-  } else {
-			rc = setup(&db);
-      // Execute the main menu function
-	    mainmenu(db);
-  }
-
-  return 0;
-}
-
-// -----------------------------END MAIN-------------------------------------------------------
-int setup(sqlite3 **p_db) {
-
-	sqlite3 *db = NULL;
-  // Return code - if the database is opened or created successfully SQLITE_OK is returned
-  // otherwise an error is returned
-  int rc;
-
-#if MEMWRITE == 1
-	  rc = psqlite3_open(":memory:", &db);
-#else
-	  rc = sqlite3_open("sqltest.db", &db);
-#endif
-
-	  // Test that the return code is OK
-	  if (rc != SQLITE_OK) {
-
-	      fprintf(stderr,"Error opening sqlite3 database in memory %s\n",sqlite3_errmsg(db) );
-	      fprintf(stderr,"Clearing resoursces used for sqlite3_open\n");
-
-	      // Whether or not an error occurs when it is opened,
-	      // resources associated with the database connection
-	      // handle should be released by passing it to
-	      // sqlite3_close() when it is no longer required.
-				sqlite3_close(db);
-				fprintf(stderr,"Database closed.\n");
-
-		    // Return error code
-				//return 1;
-
-	   }
-
-		// Let us know if the database connection was succesfull.
-		fprintf(stdout,"Opened database connection succesfully\n");
-
-	  // Display the SQLite version - debug
-
-#if DEBUG == 1
-	  // The sqlite3_stmt represents a single SQL statement
-	  sqlite3_stmt *res;
-	  // Seeing if the global variable is printed
-	  fprintf(stdout,"The SQL statement is: %s\n", sSql);
-	  // The sqlite3_prepare is the constructor for the sqlite3_stmt
-	  // compile sql text into byte code that will do the work for querying
-	  // 1st arg - database connection - obtained  from sqlite3_open()
-	  // 2nd arg - zSql - statement to be compiled
-	  // 3rd arg - nByte - negative -> read up to the first zero terminator
-	  // 4th arg - *ppStmt pointing to a compiled statement that can be run with sqlite3_step()
-	  // the calling proc is responsable for deleting the SQL statement with sqlite3_finalize()
-	  // 5th arg - pzTail point to the first byte past the end of the first SQL  staement
-	  rc = sqlite3_prepare_v2(db, "SELECT sqlite_version()", -1, &res, 0);
-	  fprintf(stderr,"%d\n\r",rc);
-	  if (rc == SQLITE_ROW) {
-		  fprintf(stdout,"SQLite Version is: %s\n",sqlite3_column_text(res,0));
-	  }
-#endif
-
-	  // 3.Inserting data - calls dbInsert
-	  // 1st arg - open database handle
-	  // 2nd arg - string to insert
-
-    // update
-
-	  //if (!dbSelect(db,zSelect) ) {
-	  //	  fprintf(stdout,"Select data succesfully\n");
-	  //	  }
-
-	  // Close the database connection.
-	  //sqlite3_close(db);
-	  *p_db = db;
-	  return 0;
-}
-
-int mainmenu(sqlite3 *db) {
-	char menu[] =
-			"\n-----------------------\n"
-			"1. View database entries\n"
-			"2. Update database records\n"
-			"3. Delete database record\n"
-			"4. Insert test data.\n"
-			"\t41. From Command Line.\n"
-			"\t42. From File.\n"
-			"5. Quit\n"
-			"\n-----------------------\n";
-
-	//displaymenu
-	//promptuser/
-	//switch responses for each entry /
-	//last item should be quit as long
-	//as there are no errors
-	char response[1024];
-	char *buf;
-	int rc=0;
-	unsigned int item = 0;
-	for (;;) {
-		fputs(menu,stdout);
-
-		fputs("Enter a choice > ",stdout);
-//		fflush();
-
-		if(fgets(response, sizeof(response), stdin) == NULL) {
-			exit(1);
-		}
-		if(sscanf(response,"%u",&item) != 1) {
-			fprintf(stderr,"Error reading commnad. Please enter a valid integer\n");
-		} else {
-		switch (item) {
-			case 1:
-				buf = readline("Enter query: > ");
-				dbSelect(db, buf);
-				free(buf);
-				break;
-			case 2:
-				fputs("dbDelete`\n",stdout);
-				fgets(response, sizeof(response), stdin);
-				//dbDelete(db, response);
-				break;
-			case 3:
-				fputs("dbUpdate()\n",stdout);
-				break;
-			case 41:
-				buf = readline("Insert test data via command.\n");
-					if (!dbInsert(db,buf) ) {
-					fprintf(stdout,"Inserted data OK\n");
-					}
-				break;
-			case 42:
-					if (!dbInsert(db,sSql) ) {
-					fprintf(stdout,"Inserted data succesfully\n");
-					}
-				break;
-			case 5:
-				fputs("Quiting.\n",stdout);
-				goto Exit;
-			default:
-				fputs("Please choose a valid menu option\n",stdout);
-			}
-		}
-
-	}
-		Exit:
-	return 0;
-}
-//}
-// --------------------------- End MainMenu ---------------------------
-
-int dbInsert(sqlite3 *db, char *data) {
-
-  // Check that a database was passed and we have an open database connection
-  // Note: do not close db connection while sqlite3_exec is running
-  // Note: do not modify the sql statement while sqlite3_exec is running
-  if ( db == NULL ) {
-    fprintf(stderr,"Error with database access, exiting\n");
-    return 1;
-  }
-  char *zErrMsg = NULL;
-  // wrapper function does sqlite3_prepare(),sqlite3_step(), sqlite3_column(), sqlite3_finalize()
-  // 1st arg - an open database
-  // 2nd arg - SQL to be evaluated
-  // 3rd arg - callback function - invoked for each result row comming out of the evaluated statements
-  // int (*callback)(void*, int, char**, char**)
-  // 4th arg - 1st arg to callback function - relaying the argument to it.
-  // 5th arg - error message writte (char **)
-		int rc = sqlite3_exec(db,data,0,0,&zErrMsg);
-		// TDOD: When there is an SQL syntax error
-		// the database closes. Syntax errors should not close the DB .
-		// Determine the correct behavior.
-			if ( rc != SQLITE_OK ) {
-				fprintf(stderr, "SQL error occured: %s\n", zErrMsg);
-				sqlite3_free(zErrMsg);
-
-				return rc;
-				}
-
-  return 0;
-}
-
-
-// Select data
-// 1st arg an open db
-// 3nd arg table
-// 3rd arg condition/selection
-// rows
-// --------------------------- dbSelect ---------------------------
-
-int dbSelect(sqlite3 *db, char *data) {
-  // Note: does not use the wrapper function (test) -
-  // pointer to a prepared statement - called by prepare
-  sqlite3_stmt *res;
-
-  // Check that a database was passed and we have an open database connection
-  if ( db == NULL ) {
-    fprintf(stderr,"Error with database access, exiting\n");
-    return 1;
-  }
-  char *zErrMsg = NULL;
-  int rc = 0;
-  //1. Prepare
-  // int rc = sqlite3_prepare_v2(db,data,-1,&res,0);
-#if DEBUG == 1
-  fprintf(stderr,"Database is: %s ; Data is: %s, ; Return Code is: %d ; stmt is %p\n",
-		  db,data,rc,res);
-#endif
-
-  rc = sqlite3_prepare_v2(db, data, -1, &res, 0);
-
-#if DEBUG == 1
-  fprintf(stderr,"Database is: %s ; Data is: %s, ; Return Code is: %d ; stmt is %p\n",
-		  db,data,rc,res );
-#endif
-  // On success the sqlite3_prepare() returns SQLITE_OK
-  if ( rc != SQLITE_OK ) {
-	 fprintf(stderr, "SQL error occured: %s with code %d\n", zErrMsg, rc);
-	 sqlite3_free(zErrMsg);
-
-	 return 1;
-  }
-
-  //2.Step
-  // 1st arg - pointed data by sqlite_stmt
-  // returns integer - the result of the operation
-  // Useful routines;
-  rc = sqlite3_step(res);
-		  for ( int i = 0; i < sqlite3_data_count(res) ; i++ ) {
-	       fprintf(stdout,"| %s\t",sqlite3_column_origin_name(res,i));
-	  }
-	  fprintf(stdout,"\r\n");
-  while ( rc == SQLITE_ROW ) {
-	  int i = 0;
-  // If the return code is SQLITE_ROW we can now iterate thorugh the entire column, row by row
-    // - sqlite3_data_count() will return 0 if sqlite3_step was not called
-	  for ( i = 0; i < sqlite3_data_count(res) ; i++ ) {
-	       fprintf(stdout,"| %s\t",sqlite3_column_text(res,i));
-	   }
-	  fprintf(stdout,"\r\n");
-  // Grab next row
-	 rc = sqlite3_step(res);
-   }
-  // Finalize - clean up after using.
-  rc = sqlite3_finalize(res);
-  if ( rc != SQLITE_OK ) {
-	  fprintf(stderr,"SQL error occured on sqlite3_finalize(): %s with code: %d\n",zErrMsg, rc);
-	  sqlite3_free(zErrMsg);
-
-	  return 1;
-  }
-
-
-  return 0;
-}
-
-#if 0
-static int callback(void *data, int argc, char **argv, char **azColName ) {
-
-
-  return 0;
-}
-#endif
-// --------------------------- dbUpdate ---------------------------
-int dbUpdate (sqlite3 *db, char *data) {
-   sqlite3_stmt *res;
-   // Vars
-   const char *msg = "Called callback function\n";
-   char *zErrMsg = NULL;
-   int rc = 0;
-   // Check that db is presnet
-   if ( db == NULL ) {
-    fprintf(stderr,"Error with database access, exiting\n");
-    return 1;
-   }
-   // Prepare & check
-   rc = sqlite3_prepare_v2(db, data, -1, &res, 0);
-			if (rc != SQLITE_OK) {
-			fprintf(stderr, "SQL error occured: %s with code %d\n", zErrMsg, rc);
-			sqlite3_free(zErrMsg);
-
-			return 1;
-			}
-//    rc = sqlite3_exec (db, data,callback,(void*) msg, &zErrMsg);
-    fprintf(stdout,"%d\n",rc);
-
-   return 0;
-}
-// Delete data
diff --git a/graph/db/sqltest.o b/graph/db/sqltest.o
deleted file mode 100644
index f74389a..0000000
Binary files a/graph/db/sqltest.o and /dev/null differ
diff --git a/graph/db/sqltest2.c b/graph/db/sqltest2.c
deleted file mode 100644
index ff86fe6..0000000
--- a/graph/db/sqltest2.c
+++ /dev/null
@@ -1,159 +0,0 @@
-#include <stdio.h> // fprintf, printf
-//#include "../../local/include/sqlite3.h"
-#include <sqlite3.h>
-
-  // Set a glbal string that will hold some SQL sample
-  // data
-
-#define DEBUG 0
-#define MEMWRITE 0
-
-  // sample test data
-char *sSql = "DROP TABLE IF EXISTS Friends;"
-            "CREATE TABLE Friends(Id INTEGER PRIMARY KEY, Name TEXT);"
-            "INSERT INTO Friends(Name) VALUES ('Tom');"
-            "INSERT INTO Friends(Name) VALUES ('Rebecca');"
-            "INSERT INTO Friends(Name) VALUES ('Jim');"
-            "INSERT INTO Friends(Name) VALUES ('Roger');"
-            "INSERT INTO Friends(Name) VALUES ('Robert');";
-int dbInsert(sqlite3 *db, char *data);
-int (*callback)()
-// --------------------------------------------------------------------------------------------------
-
-int dbInsert(sqlite3 *db, char *data) {
-  // Check that a database was passed and we have an open database connection
-  // Note: do not close db connection while sqlite3_exec is running
-  // Note: do not modify the sql statement while sqlite3_exec is running
-  if ( db == NULL ) {
-    fprintf(stderr,"Error with database access, exiting\n");
-    return 1;
-  }
-  char *zErrMsg = NULL;
-  // wrapper function does sqlite3_prepare(),sqlite3_step(), sqlite3_column(), sqlite3_finalize()
-  // 1st arg - an open database
-  // 2nd arg - SQL to be evaluated
-  // 3rd arg - callback function - invoked for each result row comming out of the evaluated statements
-  // int (*callback)(void*, int, char**, char**)
-  // 4th arg - 1st arg to callback function - relaying the argument to it.
-  // 5th arg - error message writte (char **)
-  int rc = sqlite3_exec(db,data,0,0,&zErrMsg);
-  if ( rc != SQLITE_OK ) {
-         fprintf(stderr, "SQL error occured: %s\n", zErrMsg);
-         sqlite3_free(zErrMsg);
-         sqlite3_close(db);
-
-         return 1;
-  }
-
-  return 0;
-}
-
-
-// Select data
-
-  // Select and return row(s) of data
-  // 1st arg - an open database - sqlite3_prepare
-int dbSelectData(sqlite3 *db,char *zSql) {
-  // prepare
-
-  // step
-
-  // column
-
-  // finalize
-
-  // return
-}
-
-// Update data
-// Delete data
-// --------------------------------------------------------------------------------------------------
-
-int main(int argc, char **argv) {
-
-  // 1. Definitions
-  // Each opened SQLite database is represented by a pointer
-  // to an instance of the opaque structure named sqlite3
-  sqlite3 *db;
-
-  // Return code - if the database is opened or created succesfully SQLITE_OK is returned
-  // otherwise an error is returned
-  int rc;
-
-  // This string will hold the english language of the error description
-  char *zErrMsg;
-
-  // Ensure that the proper arguments are given.`
-  if (argc != 3) {
-      fprintf(stderr, "Usage: %s DATABASE SQL-STATEMENT\n", argv[0]);
-      // Return error code
-      return 1;
-
-  }
-
-  // 2. Get the return code from sqlite3_open
-
-#if MEMWRITE == 1
-  rc = sqlite3_open(":memory:", &db);
-#else
-  rc = sqlite3_open("sqltest.db", &db);
-#endif
-
-  // Test that the return code is OK
-  if (rc != SQLITE_OK) {
-
-      fprintf(stderr,"Error opening sqlite3 database in memory %s\n",sqlite3_errmsg(db) );
-      fprintf(stderr,"Clearing resoursces used for sqlite3_open\n");
-
-      // Whether or not an error occurs when it is opened,
-      // resources associated with the database connection
-      // handle should be released by passing it to
-      // sqlite3_close() when it is no longer required.
-      sqlite3_close(db);
-      fprintf(stderr,"Database closed.\n");
-
-     // Return error code
-     return 1;
-
-   }
-
- // Let us know if the database connection was succesfull.
- fprintf(stdout,"Opened database connection succesfully\n");
-
-  // Display the SQLite version - debug
-
-#if DEBUG == 1
-  // The sqlite3_stmt represents a single SQL statement
-  sqlite3_stmt *res;
-  // Seeing if the global variable is printed
-  fprintf(stdout,"The SQL statement is: %s\n", sSql);
-  // The sqlite3_prepare is the constructor for the sqlite3_stmt
-  // compile sql text into byte code that will do the work for querying
-  // 1st arg - database connection - obtained  from sqlite3_open()
-  // 2nd arg - zSql - statement to be compiled
-  // 3rd arg - nByte - negative -> read up to the first zero terminator
-  // 4th arg - *ppStmt pointing to a compiled statement that can be run with sqlite3_step()
-  // the calling proc is responsable for deleting the SQL statement with sqlite3_finalize()
-  // 5th arg - pzTail point to the first byte past the end of the first SQL  staement
-  rc = sqlite3_prepare_v2(db, "SELECT SQLITE VERSION()", -1, &res, 0);
-  if (rc == SQLITE_ROW) {
-          fprintf(stdout,"SQLite Version is: %s\n",sqlite3_column_text(res,0));
-  }
-#endif
-
-  // 3.Inserting data - calls dbInsert
-  // 1st arg - open database handle
-  // 2nd arg - string to insert
-  if (!dbInsert(db,sSql) ) {
-        fprintf(stdout,"Inserted data succesfully\n");
-  }
-
-
-
-
-
-  // Close the database connection.
-  sqlite3_close(db);
-  return 0;
-
-}
diff --git a/graph/ds/ds2.c b/graph/ds/ds2.c
index 16c8274..6912ea3 100644
--- a/graph/ds/ds2.c
+++ b/graph/ds/ds2.c
@@ -3,16 +3,19 @@
 
 #define STRSIZE 80
 char string[STRSIZE] = "test__";
-char s1[STRSIZE] = "0000010";
-char s2[STRSIZE] = "010";
+char s1[STRSIZE] = "abcdefghijk";
+char s2[STRSIZE] = "f";
+char *strct(char* str1, char* str2);
+char *subtr (char *str1, int i, int j, char *str2);
 
 int strln(char str[]);
 int strpos(char str1[],char str2[]);
 
-
 int main () {
   fprintf(stdout,"String length is: %d\n",strln(string));
   fprintf(stdout,"String position is: %d\n",strpos(s1,s2));
+  fprintf(stdout,"String concatenation is: %s\n",strct(s1,s2));
+  fprintf(stdout,"Sub-string is: %s\n",subtr(s1,2,4,s2));
   return EXIT_SUCCESS;
 }
 
@@ -30,9 +33,45 @@ strln(char str[]) {
   }
   return i;
 }
+char *strct(char* str1, char* str2) {
+  /*****
+  *	The result of concatenation of two strings
+  * consists of the characters of the first
+  * followed by the characters of the second
+  * The function sets str1 to the concatenation of str1 and str2
+  *****/
+  int i;
+  int j;
 
-int
-strpos(char str1[],char str2[]) {
+  for (i=0; str1[i] != '\0'; i++)
+    printf("\n i is %d  str1[i] is %c\t", i,str1[i]);
+    ;
+  for (j=0; str2[j] != '\0'; str1[i+
+  +] = str2[j++])
+    printf("\nj is %d\t  str2[j] is %c\t\n ", j,str2[j]);
+    ;
+  return str1;
+}
+char *subtr (char *str1, int i, int j, char *str2) {
+  int k;
+  int m;
+
+  for ( k = i, m = 0;m < j; str2[m++] = str1[k++]) {
+      ;
+  }
+  str2[m] = '\0';
+  return str2;
+}
+/**
+* @brief Brief description of class or function (fits a single line)
+* @ingroup
+*
+* @params[in]:
+* @params[out]:
+* @return:
+*/
+
+int strpos(char str1[],char str2[]) {
   /*****
   * Param: two strings
   *	Return: integer, starting location of