Google Search

Friday, June 10, 2016

C program to copy one file to another file

‪#‎include‬<stdio.h>
#include<process.h>
void main() {
FILE *fp1, *fp2;
char a;
clrscr();
fp1 = fopen("test.txt", "r");
if (fp1 == NULL) {
puts("cannot open this file");
exit(1);
}
fp2 = fopen("test1.txt", "w");
if (fp2 == NULL) {
puts("Not able to open this file");
fclose(fp1);
exit(1);
}
do {
a = fgetc(fp1);
fputc(a, fp2);
} while (a != EOF);
fcloseall();
getch();
}

Program of reversing a string using stack

‪#‎include‬<stdio.h>
#include<string.h>
#include<stdlib.h>
‪#‎define‬ MAX 20
int top = -1;
char stack[MAX];
char pop();
void push(char);
main()
{
char str[20];
unsigned int i;
printf(“Enter the string : ” );
gets(str);
/*Push characters of the string str on the stack */
for(i=0;i<strlen(str);i++)
push(str[i]);
/*Pop characters from the stack and store in string str */
for(i=0;i<strlen(str);i++)
{
str[i]=pop();
printf(“Reversed string is : “);
puts(str);
}/*End of main()*/
void push(char item)
{
if(top == (MAX-1))
{
printf(“Stack Overflow\n”);
return;
}
stack[++top] =item;
}/*End of push()*/
char pop()
{
if(top == -1)
{
printf(“Stack Underflow\n”);
exit(1);
}
return stack[top–];
}/*End of pop()*/

Work breakdown structure (WBS)

A work breakdown structure (WBS), in project management and systems engineering, is a deliverable-oriented decomposition of a project into smaller components. A work breakdown structure is a key project deliverable that organizes the team's work into manageable sections. The Project Management Body of Knowledge (PMBOK 5) defines the work breakdown structure as a "A hierarchical decomposition of the total scope of work to be carried out by the project team to accomplish the project objectives and create the required deliverables."
A work breakdown structure element may be a product, data, service, or any combination thereof. A WBS also provides the necessary framework for detailed cost estimating and control along with providing guidance for schedule development and control.

Who calls the main() function in C/C++?

a. You need either a definition or a prototype in order to properly call a function, but "main" must never be called from any other function, so it must not be declared.
b. Because the C standard says so. Operating systems pass the return value to the calling program (usually the shell). Some compilers will accept void main, but this is a non-standard extension (it usually means "always return zero to the OS")
c. By convention, a non-zero return value signals that an error occurred. Shell scripts and other programs can use this to find out if your program terminated successfully.

What are the roles of C/C++ runtime environment during the life cycle of C/C++ program?

Runtime environment is critical for your program. there is always a default environment whenever you run a program. which collects, links and uses static and dynamic libraries. If you set any environment variable in shell, you can change the path and give your own path linking and executing the latest libraries in the program. You can check out LIBPATH, which can give you an idea , how program links to latest library in the system and how it gets the other environment essentials through Shell defined variables.

Multiplication of two polynomials using Linked List (By C)

‪#‎include‬<stdio.h>
#include<stdlib.h>
typedef struct node
{
int coeff;
int exp;
struct node* next;
} node;
void get_data(node* head)
{
int ch;
do {
printf("\nEnter the coeff : ");
scanf("%d",&(head->coeff));
printf("\nEnter the exponent : ");
scanf("%d",&(head->exp));
head->next = NULL;
printf("\nWant to enter more data? (0/1) :");
scanf("%d",&ch);
if(ch) {
head->next = (node*)malloc(sizeof(node));
head = head->next;
head->next = NULL;
}
} while(ch);
}
void display(node* head)
{
while(head->next != NULL)
{
printf("(%d.x^%d)+",head->coeff,head->exp);
head = head->next;
}
printf("(%d.x^%d)\n",head->coeff, head->exp);
}
node* add(node* result, node* poly1, node* poly2)
{
node* temp,*temp1;
temp = result;
while(poly1 && poly2)
{
if(poly1->exp > poly2->exp)
{
result->exp = poly1->exp;
result->coeff = poly1->coeff;
poly1=poly1->next;
}
else if(poly1->exp < poly2->exp)
{
result->exp = poly2->exp;
result->coeff = poly2->coeff;
poly2=poly2->next;
}
else
{
result->exp = poly1->exp;
result->coeff = poly1->coeff + poly2->coeff;
poly1 = poly1->next;
poly2 = poly2->next;
}
if(poly1 || poly2)
{
result->next = (node*)malloc(sizeof(node));
result = result->next;
result->next = NULL;
}
}
while(poly1 || poly2)
{
if(poly1)
{
result->coeff = poly1->coeff;
result->exp = poly1->exp;
poly1 = poly1->next;
}
if(poly2)
{
result->coeff = poly2->coeff;
result->exp = poly2->exp;
poly2 = poly2->next;
}
if(~(poly1 || poly2))
{
break;
}
result->next = (node*)malloc(sizeof(node));
result = result->next;
result->next = NULL;
}
while(result)
{
temp1 = result;
result = result->next;
free(temp1);
}
return temp;
}
node* multiply(node* result, node* poly1, node* poly2)
{
node* ptr,*new,*result1;
node* temp = poly2;
node* temp1 = (node*)malloc(sizeof(node));
ptr = (node*)malloc(sizeof(node));
new = ptr ;
result1 = result;
ptr->next = NULL;
while(poly1 != NULL)
{
while(poly2 != NULL)
{
ptr->coeff = (poly1->coeff) * (poly2->coeff);
ptr->exp = poly1->exp + poly2->exp;
poly2 = poly2->next;
if(poly2)
{
ptr->next = (node*)malloc(sizeof(node));
ptr = ptr->next;
ptr->next = NULL;
}
}
poly2 = temp;
result = add(temp1,new,result1);
result1 = temp1;
poly1 = poly1->next;
ptr = new;
}
while(ptr)
{
new=ptr;
ptr=ptr->next;
free(new);
}
return(result);
}
int main()
{
node* poly1 = (node*)malloc(sizeof(node));
node* result = (node*)malloc(sizeof(node));
node* poly2 = (node*)malloc(sizeof(node));
node* temp;
result->next = NULL;
result->coeff = 0;
result->exp = 0;
get_data(poly1);
display(poly1);
get_data(poly2);
display(poly2);
//printf("\nThe sum is : ");
//add(result,poly1,poly2);
//display(result);
printf("\nThe product is : ");
result = multiply(result, poly1, poly2);
display(result);
while(result)
{
temp = result;
result = result->next;
free(temp);
}
while(poly1)
{
temp = poly1;
poly1 = poly1->next;
free(temp);
}
while(poly2)
{
temp = poly2;
poly2 = poly2->next;
free(temp);
}
return 0;
}

Explain user account control (UAC)

User Account Control (UAC) is a feature in Windows that can help you stay in control of your computer by informing you when a program makes a change that requires administrator-level permission. UAC works by adjusting the permission level of your user account. If you’re doing tasks that can be done as a standard user, such as reading e‑mail, listening to music, or creating documents, you have the permissions of a standard user—even if you’re logged on as an administrator.
When changes are going to be made to your computer that require administrator-level permission, UAC notifies you. If you are an administrator, you can click Yes to continue. If you are not an administrator, someone with an administrator account on the computer will have to enter their password for you to continue. If you give permission, you are temporarily given the rights of an administrator to complete the task and then your permissions are returned back to that of a standard user. This makes it so that even if you're using an administrator account, changes cannot be made to your computer without you knowing about it, which can help prevent malicious software (malware) and spyware from being installed on or making changes to your computer.