Raghav Solutions

Raghav Solutions Raghav Solutions provides Training in Various programming languages like C,C++,Visual studio.Net, PHP for B.E.,B.C.A. M.C.A. and other technical students.

03/06/2021
वेबसाइट का कार्य खरगोन मे सबसे न्यूनतम दरों पर आपके व्यापार, संस्था या व्यक्तिगत पोर्टफोलियो के लिए संपर्क करे ।
06/07/2020

वेबसाइट का कार्य खरगोन मे सबसे न्यूनतम दरों पर आपके व्यापार, संस्था या व्यक्तिगत पोर्टफोलियो के लिए संपर्क करे ।

28/04/2020

अगली ऑनलाइन क्लास CPP या Java?
आप बतायें 👍

27/04/2020

// Read Data from a existing File

# include
# include

int main( )
{

// Declare the file pointer
FILE *fp ;

// Declare the variable for the data to be read from file
char data[50];

// Open the existing file using fopen()
// in read mode using "r" attribute
fp = fopen("demotest.txt", "r") ;

// Check if this fp is null
// which maybe if the file does not exist
if ( fp == NULL )
{
printf( "demotest.txt file failed to open." ) ;
}
else
{

printf("The file is now opened.\n") ;

// Read the data from the file
// using fgets() method
while( fgets ( data, 50, fp ) != NULL )
{

// Print the data
printf( "%s" , data ) ;
}

// Closing the file using fclose()
fclose(fp) ;

printf("Data successfully read from file demotest.txt\n");
printf("The file is now closed.") ;
}
return 0;
}

27/04/2020

////Program for Writing Data into file
# include
# include
int main( )
{

// Declare the file pointer
FILE *fp ;

// Get the data to be written in file
char data[50] = "HELLO Students Testing Data";

// Open the existing file demotest.txt using fopen()
// in write mode using "w" attribute
fp = fopen("demotest.txt", "w") ;

// Check if this fp is null
// which maybe if the file does not exist
if ( fp == NULL )
{
printf( "demo test file failed to open." ) ;
}
else
{

printf("The file is now opened.\n") ;

// Write the data into the file
if ( strlen ( data ) > 0 )
{

// writing in the file using fputs()
fputs(data, fp) ;
fputs("\n", fp) ;
}

// Closing the file using fclose()
fclose(fp) ;

printf("Data successfully written in file\n");
printf("The file is now closed.") ;
}
return 0;
}

File Handling
27/04/2020

File Handling

25/04/2020

//Demostration of Structure and Union Size Comparision


union unionDemo
{
//defining a union
//char name[10];
float salary;
int id;
} u_instance;

struct structDemo
{
//char name[10];
float salary;
int id;
} s_instance;

int main()
{
printf("size of union = %d bytes", sizeof(u_instance));
printf("\nsize of structure = %d bytes", sizeof(s_instance));
return 0;
}

Saturday Class Content
25/04/2020

Saturday Class Content

24/04/2020

//Structure Demostration


/*structure creation*/
struct student
{
char name[50]; // structure member1
int id; // structure member2
char branch[20]; // structure member3
int age; // structure member4
char place[50]; // structure member5
} std; // structure variable
int main()
{
/*Taking information from keyboard and store it by using structure variable std*/
printf("Enter Student Information\n");
printf("----------------------------\n");
printf("enter name :");
scanf("%s",std.name);

printf("enter id :");
scanf("%d",&std.id);

printf("enter branch name :");
scanf("%s",std.branch);

printf("enter age :");
scanf("%d",&std.age);

printf("enter location :");
scanf("%s",std.place);

/*Displaying student information */
//Accessing information by using structure variable std
printf("Displaying Student Information\n");
printf("----------------------------\n");

printf(" name: %s\n", std.name);
printf(" id: %d \n", std.id);
printf(" branch: %s \n", std.branch);
printf(" age: %d\n", std.age);
printf(" place: %s \n", std.place);

return 0;
}

24/04/2020

//Realloc Example



int main()
{
int *ptr, i , n1, n2;
printf("Enter size: ");
scanf("%d", &n1);

ptr = (int*) malloc(n1 * sizeof(int));

printf("Addresses of previously allocated memory: ");
for(i = 0; i < n1; ++i)
printf("%u\n",ptr + i);
printf("\nEnter the new size: ");
scanf("%d", &n2);
// rellocating the memory
ptr = realloc(ptr, n2 * sizeof(int));
printf("Addresses of newly allocated memory: ");
for(i = 0; i < n2; ++i)
printf("%u\n", ptr + i);

free(ptr);

return 0;
}

24/04/2020

//Calloc Example



int main()
{
int n, i, *ptr, sum = 0;
printf("Enter number of elements: ");
scanf("%d", &n);
ptr = (int*) calloc(n, sizeof(int));
if(ptr == NULL)
{
printf("Error! memory not allocated.");
exit(0);
}
printf("Enter elements: ");
for(i = 0; i < n; ++i)
{
scanf("%d", ptr + i);
sum += *(ptr + i);
}
printf("Sum = %d", sum);
free(ptr);
return 0;

}

Dynamic Memory Allocation Functions(Continued...)
24/04/2020

Dynamic Memory Allocation Functions(Continued...)

Address

Khargone
451001

Opening Hours

Monday 5pm - 9pm
Tuesday 5pm - 9pm
Wednesday 5pm - 9pm
Thursday 5pm - 9pm
Friday 5pm - 9pm
Saturday 5pm - 9pm

Telephone

+919826501981

Website

Alerts

Be the first to know and let us send you an email when Raghav Solutions posts news and promotions. Your email address will not be used for any other purpose, and you can unsubscribe at any time.

Shortcuts

Share