code cleanup to prevent gcc warnings

This commit is contained in:
Krishna Vedala 2020-04-08 09:41:12 -04:00
parent 64789aed99
commit 1b826807ed
No known key found for this signature in database
GPG Key ID: BA19ACF8FC8792F7
11 changed files with 244 additions and 196 deletions

View File

@ -6,6 +6,7 @@
#include <unistd.h>
#include <string.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#define MAX 80
#define PORT 8080
#define SA struct sockaddr
@ -13,7 +14,8 @@ void func(int sockfd)
{
char buff[MAX];
int n;
for (;;) {
for (;;)
{
bzero(buff, sizeof(buff));
printf("Enter the string : ");
n = 0;
@ -23,7 +25,8 @@ void func(int sockfd)
bzero(buff, sizeof(buff));
read(sockfd, buff, sizeof(buff));
printf("From Server : %s", buff);
if ((strncmp(buff, "exit", 4)) == 0) {
if ((strncmp(buff, "exit", 4)) == 0)
{
printf("Client Exit...\n");
break;
}
@ -37,7 +40,8 @@ int main()
// socket create and varification
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd == -1) {
if (sockfd == -1)
{
printf("socket creation failed...\n");
exit(0);
}
@ -51,7 +55,8 @@ int main()
servaddr.sin_port = htons(PORT);
// connect the client socket to server socket
if (connect(sockfd, (SA*)&servaddr, sizeof(servaddr)) != 0) {
if (connect(sockfd, (SA *)&servaddr, sizeof(servaddr)) != 0)
{
printf("connection with the server failed...\n");
exit(0);
}

View File

@ -18,11 +18,12 @@ int decimal_to_octal(int decimal)
return ((decimal_to_octal(decimal / 8) * 10) + decimal % 8);
}
}
void main()
int main()
{
int octalNumber, decimalNumber;
printf("\nEnter your decimal number : ");
scanf("%d", &decimalNumber);
octalNumber = decimal_to_octal(decimalNumber);
printf("\nThe octal of %d is : %d", decimalNumber, octalNumber);
return 0;
}

View File

@ -2,19 +2,31 @@
#include <stdlib.h>
#include <time.h>
void swap(int *a, int *b)
{int t;t =*a;*a=*b;*b=t;}
{
int t;
t = *a;
*a = *b;
*b = t;
}
int part(int a[], int l, int r, int n, int pivot, int pindex)
{int p1=l,p2=r;
{
int p1 = l, p2 = r;
while (p2 > p1)
{
if (a[p1] > pivot && a[p2] < pivot)
{swap(&a[p1],&a[p2]);}
{
swap(&a[p1], &a[p2]);
}
else
{
if (a[p1] <= pivot)
{p1++;}
{
p1++;
}
if (a[p2] >= pivot)
{p2--;}
{
p2--;
}
}
}
swap(&a[pindex], &a[p2]);
@ -30,25 +42,36 @@ int rselect(int a[],int l,int r,int n,int o)
pactual = part(a, l, r, n, pivot, pindex);
if (pactual == o)
{return a[pactual];}
{
return a[pactual];
}
if (o < pactual)
{rselect(a,l,pactual-1,n,o);}
{
rselect(a, l, pactual - 1, n, o);
}
if (o > pactual)
{rselect(a,pactual+1,r,n,o-pactual);}
{
rselect(a, pactual + 1, r, n, o - pactual);
}
}
if (r == l)
{return a[l];}
{
return a[l];
}
return -1;
}
int main()
{srand(time(NULL));
{
srand(time(NULL));
int n, o, i, *a;
scanf("%d %d", &n, &o);
a = (int *)malloc(n * sizeof(int));
for (i = 0; i < n; i++)
{scanf("%d",a+i);}
{
scanf("%d", a + i);
}
printf("\n\n%d", rselect(a, 0, n - 1, n, o));
return 0;
}

View File

@ -7,7 +7,6 @@
#include <stdio.h>
void strng(int a)
{
int j = a;
@ -29,10 +28,11 @@ void strng(int a)
else
printf("%d is not a strong number", j);
}
void main()
int main()
{
int a;
printf("Enter the number to check");
scanf("%d", &a);
strng(a);
return 0;
}

View File

@ -6,47 +6,61 @@ e.g. for 10, largest prime factor = 5. For 17, largest prime factor = 17.
#include <stdio.h>
#include <math.h>
int isprime(int no) {
int isprime(int no)
{
int sq;
if (no == 2) {
if (no == 2)
{
return 1;
}
else if (no%2 == 0) {
else if (no % 2 == 0)
{
return 0;
}
sq = ((int)(sqrt(no))) + 1;
for (int i = 3; i < sq; i + 2) {
if (no%i == 0) {
for (int i = 3; i < sq; i += 2)
{
if (no % i == 0)
{
return 0;
}
}
return 1;
}
int main() {
int main()
{
int maxNumber = 0;
int n = 0;
int n1;
scanf("%d", &n);
if (isprime(n) == 1)
printf("%d", n);
else {
while (n % 2 == 0) {
else
{
while (n % 2 == 0)
{
n = n / 2;
}
if (isprime(n) == 1) {
if (isprime(n) == 1)
{
printf("%d\n", n);
}
else {
else
{
n1 = ((int)(sqrt(n))) + 1;
for (int i = 3; i < n1; i + 2) {
if (n%i == 0) {
if (isprime((int)(n / i)) == 1) {
for (int i = 3; i < n1; i += 2)
{
if (n % i == 0)
{
if (isprime((int)(n / i)) == 1)
{
maxNumber = n / i;
break;
}
else if (isprime(i) == 1) {
else if (isprime(i) == 1)
{
maxNumber = i;
}
}

View File

@ -1,28 +1,34 @@
#include <stdio.h>
unsigned long gcd(unsigned long a, unsigned long b) {
unsigned long gcd(unsigned long a, unsigned long b)
{
unsigned long r;
if (a > b) {
if (a > b)
{
unsigned long t = a;
a = b;
b = t;
}
while (r = a % b) {
while ((r = (a % b)))
{
a = b;
b = r;
}
return b;
}
unsigned long lcm(unsigned long a, unsigned long b) {
unsigned long lcm(unsigned long a, unsigned long b)
{
unsigned long long p = (unsigned long long)a * b;
return p / gcd(a, b);
}
int main(void) {
int main(void)
{
unsigned long ans = 1;
unsigned long i;
for (i = 1; i <= 20; i++) {
for (i = 1; i <= 20; i++)
{
ans = lcm(ans, i);
}
printf("%lu\n", ans);

View File

@ -3,9 +3,6 @@
#ifdef _OPENMP
#include <omp.h>
#pragma message ("Using OpenMP parallelization")
#else
#pragma message ("Not using OpenMP parallelization")
#endif
/**

View File

@ -1,22 +1,26 @@
#include <stdio.h>
int linearsearch(int *arr, int size, int val){
int linearsearch(int *arr, int size, int val)
{
int i;
for (i = 0; i < size; i++){
for (i = 0; i < size; i++)
{
if (arr[i] == val)
return 1;
}
return 0;
}
void main(){
int main()
{
int n, i, v;
printf("Enter the size of the array:\n");
scanf("%d", &n); //Taking input for the size of Array
int a[n];
printf("Enter the contents for an array of size %d:\n", n);
for (i = 0; i < n; i++) scanf("%d", &a[i]);// accepts the values of array elements until the loop terminates//
for (i = 0; i < n; i++)
scanf("%d", &a[i]); // accepts the values of array elements until the loop terminates//
printf("Enter the value to be searched:\n");
scanf("%d", &v); //Taking input the value to be searched
@ -24,4 +28,5 @@ void main(){
printf("Value %d is in the array.\n", v);
else
printf("Value %d is not in the array.\n", v);
return 0;
}

View File

@ -2,7 +2,6 @@
#include <stdlib.h>
#define len 5
int binarySearch(int array[], int leng, int searchX)
{
int pos = -1, right, left, i = 0;
@ -29,8 +28,7 @@ int binarySearch(int array[], int leng, int searchX)
return -1; /* not found */
}
void main(int argc, char *argv[])
int main(int argc, char *argv[])
{
int array[len] = {5, 8, 10, 14, 16};
@ -44,5 +42,5 @@ void main(int argc, char *argv[])
printf("The number %d exist in array at position : %d \n", 5, position);
}
return 0;
}

View File

@ -1,7 +1,7 @@
#include <stdio.h>
void stoogesort(int[], int, int);
void main()
int main()
{
int arr[100], i, n;
@ -16,9 +16,9 @@ void main()
printf("%d ", arr[i]);
}
printf("\n");
return 0;
}
void stoogesort(int arr[], int i, int j)
{
int temp, k;

View File

@ -259,7 +259,7 @@ void insert2(char *s)
Tptr pp, *p;
p = &root;
while (pp = *p)
while (pp == *p)
{
if ((d = *s - pp->splitchar) == 0)
{
@ -390,7 +390,6 @@ void nearsearch(Tptr p, char *s, int d)
nearsearch(p->hikid, s, d);
}
#define NUMBER_OF_STRING 3
int main(int argc, char *argv[])