Algorithms_in_C  1.0.0
Set of algorithms implemented in C.
client.c File Reference

Client side implementation of Server-Client system. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/socket.h>
#include <unistd.h>
Include dependency graph for client.c:

Macros

#define MAX   80
 max. More...
 
#define PORT   8080
 port number to connect to
 
#define SA   struct sockaddr
 shortname for sockaddr
 

Functions

void func (int sockfd)
 Continuous loop to send and receive over the socket. More...
 
int main ()
 Driver code.
 

Detailed Description

Client side implementation of Server-Client system.

Author
Nairit11
Krishna Vedala
See also
client_server/server.c

Macro Definition Documentation

◆ MAX

#define MAX   80

max.

characters per message

Function Documentation

◆ func()

void func ( int  sockfd)

Continuous loop to send and receive over the socket.

Exits when "exit" is sent from commandline.

Parameters
sockfdsocket handle number
38 {
39  char buff[MAX];
40  int n;
41  for (;;)
42  {
43  bzero(buff, sizeof(buff));
44  printf("Enter the string : ");
45  n = 0;
46  while ((buff[n++] = getchar()) != '\n')
47  {
48  ;
49  }
50  write(sockfd, buff, sizeof(buff));
51  bzero(buff, sizeof(buff));
52  read(sockfd, buff, sizeof(buff));
53  printf("From Server : %s", buff);
54  if ((strncmp(buff, "exit", 4)) == 0)
55  {
56  printf("Client Exit...\n");
57  break;
58  }
59  }
60 }
main
int main(int argc, const char *argv[])
Driver Code.
Definition: selection_sort.c:69
get_next_abundant
unsigned long get_next_abundant(unsigned long N)
Find the next abundant number after N and not including N.
Definition: sol1.c:55
is_prime
char is_prime(unsigned long n)
Function to check if a number is prime.
Definition: sol1.c:11
main
int main()
Main function.
Definition: sol1.c:12
swap
void swap(int *a, int *b)
Swap two integer variables.
Definition: merge_sort.c:17
L
Definition: list.h:8
main
int main()
Main function.
Definition: jump_search.c:81
main
int main(void)
Main function.
Definition: merge_sort.c:101
is_palindromic
int is_palindromic(unsigned int n)
Check if number is palindromic.
Definition: sol.c:12
sigma2
uint64_t sigma2(uint64_t N)
compute sum of squares of all integer factors of a number
Definition: sol1.c:93
sudoku::N2
uint8_t N2
block of elements
Definition: sudoku_solver.c:36
test
static void test()
Test function.
Definition: insertion_sort.c:36
get_divisors
uint64_t get_divisors(uint64_t N, uint64_t *D)
Get all integer divisors of a number.
Definition: sol1.c:47
EPSILON
#define EPSILON
accuracy tolerance limit
Definition: qr_eigen_values.c:20
compare
int compare(const void *a, const void *b)
comparison function for use with internal qsort algorithm
Definition: sol1.c:19
jump_search
int jump_search(const int *arr, int x, size_t n)
Implement Jump-search algorithm.
Definition: jump_search.c:24
shell_sort
void shell_sort(char data[][MAX_NAME_LEN], int LEN)
Alphabetical sorting using 'shell sort' algorithm.
Definition: sol1.c:20
get_product
long long int get_product(FILE *fp, long start_pos, int num_digits)
Compute the product of two numbers in a file.
Definition: sol1.c:16
main
int main(int argc, char **argv)
main function
Definition: qr_eigen_values.c:315
divisors
static unsigned int divisors[]
Hack to store divisors between 1 & 20.
Definition: sol2.c:21
test
static void test()
Test function.
Definition: selection_sort.c:50
data
Definition: prime_factoriziation.c:25
modifiedBinarySearch
void modifiedBinarySearch(const int **mat, int n, int m, int x)
Function to perform binary search on the mid values of row to get the desired pair of rows where the ...
Definition: modified_binary_search.c:48
test
void test()
Test implementation of the function.
Definition: jump_search.c:58
display
void display(const int *arr, int n)
Display elements of array.
Definition: bubble_sort.c:17
get_perfect_number
char get_perfect_number(unsigned long N)
Definition: sol2.c:31
lcm
unsigned long lcm(unsigned long a, unsigned long b)
Compute Least Common Multiple (LCM) of two numbers.
Definition: sol3.c:41
lazy_sort
void lazy_sort(char data[][MAX_NAME_LEN], int LEN)
Alphabetical sorting using 'lazy sort' algorithm.
Definition: sol1.c:48
main
int main()
Main function.
Definition: so1.c:17
main
int main(void)
Main function.
Definition: sol.c:25
node
Node, the basic data structure in the tree.
Definition: binary_search_tree.c:15
MAX_NAME_LEN
#define MAX_NAME_LEN
Maximum length of each name.
Definition: sol1.c:15
check_number
static char check_number(unsigned long long n)
Pretty naive implementation.
Definition: sol1.c:18
min
#define min(X, Y)
Macro to return the minimum of two values.
Definition: jump_search.c:13
bead_sort
void bead_sort(int *a, size_t len)
This is where the sorting of the array takes place.
Definition: bead_sort.c:37
stats_computer1
void stats_computer1(float x, float *mean, float *variance, float *std)
continuous mean and variance computance using first value as an approximation for the mean.
Definition: realtime_stats.c:24
MOD_LIMIT
#define MOD_LIMIT
modulo limit
Definition: sol1.c:17
test2
void test2()
test function to compute eigen values of a 2x2 matrix
Definition: qr_eigen_values.c:271
remove_digits
char remove_digits(big_int *digit, int N)
Function to remove digits preceeding the current digit.
Definition: sol1.c:76
main
int main()
Main function.
Definition: sol3.c:14
sudoku::N
uint8_t N
number of elements
Definition: sudoku_solver.c:35
_big_int::value
char value
tens place (single digit)
Definition: sol1.c:19
qr_decompose
void qr_decompose(double **A, double **Q, double **R, int M, int N)
Decompose matrix using Gram-Schmidt process.
Definition: qr_decompose.h:142
add_numbers
int add_numbers(uint8_t *a, uint8_t *b, uint8_t N)
Function to add arbitrary length decimal integers stored in an array.
Definition: sol1.c:48
get_month_days
char get_month_days(short month)
Function to get the number of days in a month.
Definition: sol1.c:15
node::data
int data
data of the node
Definition: binary_search_tree.c:18
MAX_NAMES
#define MAX_NAMES
Maximum number of names to store.
Definition: sol1.c:14
is_in
char is_in(uint64_t N, uint64_t *D, uint64_t L)
Check if a number is present in given array.
Definition: sol1.c:28
Node::data
int data
stores the number
Definition: threaded_binary_trees.c:28
get_next_abundant
unsigned long get_next_abundant(unsigned long N)
Find the next abundant number after N and not including N.
Definition: sol2.c:70
Node
Node, the basic data structure of the tree.
Definition: threaded_binary_trees.c:27
test1
void test1()
test function to compute eigen values of a 2x2 matrix
Definition: qr_eigen_values.c:224
swap
void swap(int *first, int *second)
Swapped two numbers using pointer.
Definition: selection_sort.c:16
test_function
void test_function(const float *test_data, const int number_of_samples)
Test the algorithm implementation.
Definition: realtime_stats.c:92
MAX_DIGITS
#define MAX_DIGITS
maximum number of digits
Definition: sol1.c:13
sum_of_primes
unsigned long long sum_of_primes(unsigned long N)
Computes sum of prime numbers less than N.
Definition: sol1.c:21
bubbleSort
void bubbleSort(int *arr, int size)
Bubble sort algorithm implements using recursion.
Definition: bubble_sort_recursion.c:29
merge
void merge(int *a, int l, int r, int n)
Perform merge of segments.
Definition: merge_sort.c:33
main
int main()
Driver code.
Definition: client.c:70
qr_decompose.h
Library functions to compute QR decomposition of a given matrix.
swap
void swap(int *first, int *second)
Swap two values by using pointer.
Definition: bubble_sort.c:31
_big_int::next_digit
struct _big_int * next_digit
hundreds place
Definition: sol1.c:20
get_digits
unsigned int get_digits(unsigned char *number)
Get number of digits in a large number.
Definition: sol1.c:75
insertionSort
void insertionSort(int *arr, int size)
Insertion sort algorithm implements.
Definition: insertion_sort.c:16
is_abundant
unsigned long is_abundant(unsigned long N)
Is the given number an abundant number (1) or not (0)
Definition: sol1.c:47
print_matrix
void print_matrix(double **A, int M, int N)
function to display matrix on stdout
Definition: qr_decompose.h:22
print_number
int print_number(uint8_t *number, uint8_t N, int8_t num_digits_to_print)
Function to print a long number.
Definition: sol1.c:92
test
void test()
Test function.
Definition: bubble_sort.c:70
sum_of_divisors
unsigned long sum_of_divisors(unsigned int N)
function to return the sum of proper divisors of N
Definition: sol1.c:13
binarySearch
int binarySearch(const int **mat, int i, int j_low, int j_high, int x)
This function does Binary search for x in i-th row from j_low to j_high.
Definition: modified_binary_search.c:18
sigma
uint64_t sigma(uint64_t N)
sum of squares of factors of numbers from 1 thru N
Definition: sol1.c:114
isprime
char isprime(int no)
Check if the given number is prime.
Definition: sol1.c:15
big_int
struct _big_int big_int
store arbitratily large integer values as a linked list of digits.
main
int main(void)
main function
Definition: qr_decomposition.c:18
MAX_LENGTH
#define MAX_LENGTH
chunk size of array allocation
Definition: sol1.c:18
main
int main(int argc, char **argv)
Main function.
Definition: realtime_stats.c:128
main
int main()
Driver Code.
Definition: bubble_sort_recursion.c:72
mat_mul
double ** mat_mul(double **A, double **B, double **OUT, int R1, int C1, int R2, int C2)
Perform multiplication of two matrices.
Definition: qr_eigen_values.c:59
MAX_LEN
#define MAX_LEN
length of resulting recurring fraction number
Definition: sol1.c:15
display
void display(const int *arr, int n)
Displays the array, passed to this method.
Definition: bead_sort.c:23
main
int main(void)
Main function.
Definition: binary_search.c:105
MAX
#define MAX
max.
Definition: client.c:28
min
#define min(a, b)
shorthand for minimum value
Definition: kohonen_som_topology.c:43
_big_int::prev_digit
struct _big_int * prev_digit
units place
Definition: sol1.c:21
_big_int
store arbitratily large integer values as a linked list of digits.
Definition: sol1.c:18
main
int main()
Main function.
Definition: sol2.c:15
count_divisors
long count_divisors(long long n)
Get number of divisors of a given number.
Definition: sol1.c:19
max
#define max(a, b)
shorthand for maximum value
Definition: kohonen_som_topology.c:39
MAX_DENO
#define MAX_DENO
limit of unit fractions
Definition: sol1.c:14
stats_computer2
void stats_computer2(float x, float *mean, float *variance, float *std)
continuous mean and variance computance using Welford's algorithm (very accurate)
Definition: realtime_stats.c:61
is_abundant
char is_abundant(unsigned long N)
Is the given number an abundant number (1) or not (0)
Definition: sol2.c:59
display
void display(double **A, int N)
Function to display square matrix.
Definition: lu_decompose.c:66
check_number
static int check_number(unsigned long long n)
Checks if a given number is devisable by every number between 1 and 20.
Definition: sol2.c:30
number_of_paths
unsigned long long number_of_paths(int N)
At every node, there are 2 possible ways to move -> down or right.
Definition: sol1.c:17
is_sum_of_abundant
char is_sum_of_abundant(unsigned long N)
check if a given number can be represented as a sum of two abundant numbers.
Definition: sol2.c:87
get_number
int get_number(FILE *fp, char *buffer, uint8_t *out_int)
Function to read the number from a file and store it in array.
Definition: sol1.c:16
show_data
void show_data(int *arr, long len)
Helper function to print array values.
Definition: shell_sort2.c:16
main
int main(int argc, const char *argv[])
Driver Code.
Definition: bubble_sort.c:89
sudoku::a
uint8_t * a
matrix as a flattened 1D row-major array
Definition: sudoku_solver.c:34
collatz
long long collatz(long long start_num)
Computes the length of collatz sequence for a given starting number.
Definition: sol1.c:27
test
void test()
Test function.
Definition: bubble_sort_recursion.c:53
main
int main(int argc, const char *argv[])
Main function.
Definition: bead_sort.c:75
main
int main(int argc, char *argv[])
Main function.
Definition: shell_sort2.c:66
test
void test()
Test implementations.
Definition: binary_search.c:75
main
int main()
Main function.
Definition: sol4.c:12
node
struct node node
Node, the basic data structure in the tree.
gcd
unsigned long gcd(unsigned long a, unsigned long b)
Compute Greatest Common Divisor (GCD) of two numbers using Euclids algorithm.
Definition: sol3.c:18
main
int main()
Main function.
Definition: modified_binary_search.c:97
add_digit
big_int * add_digit(big_int *digit, char value)
Function that allocates memory to add another digit at the MSB.
Definition: sol1.c:37
merge_sort
void merge_sort(int *a, int n, int l, int r)
Merge sort algorithm implementation.
Definition: merge_sort.c:82
LIMS
#define LIMS
limit of range of matrix values
Definition: qr_eigen_values.c:19
binarysearch2
int binarysearch2(const int *arr, int l, int r, int x)
Iterative implementation.
Definition: binary_search.c:51
eigen_values
double eigen_values(double **A, double *eigen_vals, int mat_size, char debug_print)
Compute eigen values using iterative shifted QR decomposition algorithm as follows:
Definition: qr_eigen_values.c:106
BEAD
#define BEAD(i, j)
Create easy access of elements from a 2D matrix stored in memory as a 1D array.
Definition: bead_sort.c:16
shell_sort
void shell_sort(int *array, long LEN)
Shell sort algorithm.
Definition: shell_sort2.c:41
swap
void swap(int *first, int *second)
Swapped two numbers using pointer.
Definition: bubble_sort_recursion.c:17
is_leap_year
char is_leap_year(short year)
Check if input year is a leap year.
Definition: sol1.c:41
get_perfect_number
char get_perfect_number(unsigned long N)
Returns: -1 if N is deficient 1 if N is abundant 0 if N is perfect.
Definition: sol1.c:19
tnode
Definition: multikey_quick_sort.c:205
bubbleSort
void bubbleSort(int *arr, int size)
Bubble sort algorithm implementation.
Definition: bubble_sort.c:43
is_sum_of_abundant
char is_sum_of_abundant(unsigned long N)
check if a given number can be represented as a sum of two abundant numbers.
Definition: sol1.c:71
create_matrix
void create_matrix(double **A, int N)
create a square matrix of given size with random elements
Definition: qr_eigen_values.c:27
print
void print(CantorSet *head)
Print sets in the current range to stdout
Definition: cantor_set.c:55
selectionSort
void selectionSort(int *arr, int size)
Selection sort algorithm implements.
Definition: selection_sort.c:28
abundant_flags
char * abundant_flags
This is the global array to be used to store a flag to identify if a particular number is abundant (1...
Definition: sol2.c:24
binarysearch1
int binarysearch1(const int *arr, int l, int r, int x)
Recursive implementation.
Definition: binary_search.c:21