Tags » C Program

[C] Returnable 2D array and readfile

char** create2DCharArray(int m, int n)
{
   char* values = calloc(m*n, sizeof(char));
   char** rows = malloc(n*sizeof(char*));
   int i;
   for (i=0; i<n; ++i)
   {
       rows[i] = values + i*m;
   }
   return rows;
}

void destroy2DCharArray(char** arr)
{
   free(*arr);
   free(arr);
}

char** readFileInto2DArray ( const char* fileName )
{
   FILE *f;
   f = fopen(fileName,"r");
   char ch, strr, *str;
   int row = 0, column = 0, i = 0, j = 0;
   while(fgets(strr, sizeof strr, f))
   {
      row++;
      if(column < strlen(strr) )
           column = strlen(strr);
   }
   rewind(f);
   char** arr = create2DCharArray(column,row);
   while(i < row)
   {
     do
     {
        ch = fgetc(f);
        if ( ch == '\r')
        ch = fgetc(f);
        arr[i][j] = ch;
        j++;
     }
     while( !( ch == '\n' || ch == EOF ) );
     arr[i][--j] = '\0';
     i++;
     j = 0;
   }
   fclose(f);
   return arr;
}

How to run an external program from a python script

This blog will try to demonstrate how a python script can be used to automate the running of an external program with data input file located at a particular location. 1,967 more words

Arithmetic operations

C++ program to perform arithmetic operations :

code

#include<iostream.h>
#include<conio.h>

void main()
{
int a,b,add,sub,div,mul;
clrscr();
cout<<“Arithmetic Operations :\n”;
cout<<“\nEnter first number :”;
cin>>a;
cout<<“\nEnter second number :”; 58 more words

C Program

String palindrome / not

C program to check entered string is palindrome or not :

code

#include<stdio.h>
#include<conio.h>
void main()
{
char str;
int len,i,flag=0;
clrscr();
printf(“Enter string to check it palindrome or not :”); 51 more words

C Programs

Arithmetic operation using function

C program to perform arithmetic operation using function:

code

#include<stdio.h>

#include<conio.h>

void cal(int,int);

void main()

{

int a,b;

clrscr();

printf(“Enter first element :”);

scanf(“%d”,&a);

printf(“Enter second element :”); 73 more words

C Programs

Area of circle using function

C program to find area of circle using function :

code

#include<stdio.h>
#include<conio.h>
void area();
void main()
{
clrscr();
area();
getch();
}
void area()
{ 35 more words

C Programs

Accept & display matrix

C program to accept & display matrix element :

code

#include<stdio.h>
#include<conio.h>
void main()
{
int a[2][2];
int i,j;
clrscr();
printf(“Enter matrix element:”);
for(i=0;i<2;i++)
{ 62 more words

C Programs