User Tools

Site Tools


software_carpentary2

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
software_carpentary2 [2011/06/20 03:57]
medhamsh
software_carpentary2 [2011/06/20 04:17]
medhamsh
Line 101: Line 101:
 </​code>​ </​code>​
  
 +<​code>​
 +void main()
 +{
 +char main_str[40],​str[40];​
 +int i,​j,​len1,​len2;​
 +clrscr();
 +printf("​\n Enter the main String :");
 +gets(main_str);​
 +printf("​\n enter the String you wanna search : ");
 +gets(str);
 +len1=strlen(main_str);​
 +len2=strlen(str);​
 +i=0;
 +j=0;
 +while(str[i]!='​\0'​)
 +{
 +while(main_str[j]!='​\0'​)
 +{
 +if(str[i]==main_str[j])
 +{
 +i++;
 +if(len2==i)
 +{
 +j=j-len2+2;
 +printf("​\n found at %d location",​j);​
 +break;
 +}
 +
 +}//if
 +else
 +j++;
 +
 +}//inner while
 +if(j==len1)
 +{
 +printf("​\n not Found"​);​
 +break;
 +}//if
 +
 +}//outer while
 +getch();
 +}
 +</​code>​
 +
 +<​code>​
 +void main()
 +{
 +int a,b;
 +clrscr();
 +printf("​\n enter First Number :");
 +scanf("​%d",&​a);​
 +printf("​\n enter Second Number :");
 +scanf("​%d",&​b);​
 +swap(&​a,&​b);​
 +printf("​\n first Number is : %d",​a);​
 +printf("​\n second Number is : %d",​b);​
 +getch();
 +}
 +
 +swap(int *a,int *b)
 +{
 +*a=*a-*b;
 +*b=*a+*b;
 +*a=*b-*a;
 +
 +}
 +
 +</​code>​
 +
 +<​code>​
 +main()
 +{
 +int temps[31];
 +int index,​total;​
 +float average,​celsius;​
 +total=0.0;
 +for(index=0;​index<​31;​index++)
 +{
 +printf("​enter temperature #​%d:",​index);​
 +scanf("​%d",&​temps[index]);​
 +}
 +for(index=0;​index<​31;​index++)
 +total+=temps[index];​
 +average=total/​31.0
 +printf("​average is:​%f\n\n",​ average);
 +puts9"​fahrenheit\tcelsius\n"​);​
 +for(index=0;​index<​31;​index++)
 +{
 +celsius=(5.0/​9.0)*(temps[index]-32);​
 +printf("​%d\t\t%6.2f\n",​temps[index],​celsius);​
 +}
 +}
 +</​code>​
 +
 +<​code>​
 +#include "​stdio.h"​
 +main()
 +{
 +FILE*fp;
 +int letter;
 +if((fp=fopen("​MYFILE","​r"​))==NULL)
 +{
 +puts("​Cannot oepn the file"​);​
 +exit();
 +}
 +while((letter=fgetc(fp)) !=eof)
 +printf("​%c",​letter);​
 +fclose(fp);
 +}
 +</​code>​
 +
 +====== Make: Automated Builds ======
 +
 +The make utility
 +
 +If you run
 +
 +<​code>​
 +make
 +</​code>​
 +
 +this program will look for a file named makefile in your directory, and then execute it.
 +If you have several makefiles, then you can execute them with the command:
 +
 +<​code>​
 +make -f MyMakefile
 +</​code>​
 +
 +There are several other switches to the make utility. For more info, man make.
 +
 +===== Build Process =====
 +
 +
 +   1. Compiler takes the source files and outputs object files
 +   2. Linker takes the object files and creates an executable
 +
 +==== Compiling by hand ====
 +
 +
 +The trivial way to compile the files and obtain an executable, is by running the command:
 +<​code>​
 +g++ main.cpp hello.cpp factorial.cpp -o hello
 +</​code>​
 +
 +==== The basic Makefile ====
 +
 +
 +The basic makefile is composed of:
 +
 +<​code>​
 +target: dependencies
 +[tab] system command
 +</​code>​
 +
 +This syntax applied to our example would look like:
 +
 +<​code>​
 +all:
 + g++ main.cpp hello.cpp factorial.cpp -o hello
 +</​code>​
software_carpentary2.txt ยท Last modified: 2018/03/24 11:13 (external edit)