Showing posts with label C language. Show all posts
Showing posts with label C language. Show all posts

Thursday, December 11, 2008

Password in C Language

#include
#include
#include

int main(void) {
int length = 2;
int r,i;
int c;
srand((unsigned int)time(0)); //Seed number for rand()
for (i = 0; i < length; i++) {
r = rand() + 5;
c = (int)r;
printf("%d", c);
}
return 0;
}


--------------------
int Password::GETCH(void) {
return _getch(); // does not echo input
}

int Password::BreakPass() { //uses global var. password and ptr
char input;
int count;

count = 0;

printf("enter your password: ");

do
{

input = GETCH();
if(input == '\xD') break; // enter pressed?
putc('*', stdout);
ptr = &input;
password[count] = *ptr;
count++;

}while(count < 20);

password[count++] = '\0'; // terminate the string

printf("\nyour password: %s\n", password);

return 0;
}

My Final Project in CSC 122

#include
#include
#include

char log,sign,a;
int x,c,m,z[20];
int choice;

int main()
{

char pass[30];
char filename[30];
int balik=1;
char line1[20];
char line2[20];
char line3[20];
char line4[20];
char line5[20];
char line6[20];
int code;
char fid[20];
char fpass[20];
FILE *f;


printf("sign-in to YAHOOMAIL!\n");
printf("you are protected\n\n");
system("pause");


while(balik==1)
{
printf("enter ID:");
gets(filename);
///1
if((f=fopen(filename,"r"))!=NULL)
{
printf("error! ID exist!\n");

balik=1;
}

///1
else
{
///2
if((f=fopen(filename,"w"))==NULL)
{
printf("error ID\n");
balik=1;
}
//2
else
{


//information center

f=(fopen(filename,"w"));
printf("last name:");
gets(line1);
fprintf(f,"last name:%s\n\n",line1);


printf("first name:");
gets(line2);
fprintf(f,"first name:%s\n\n",line2);


printf("middle name:");
gets(line3);
fprintf(f,"middle name:%s\n\n",line3);


printf("age:");
gets(line4);
fprintf(f,"age:%s\n\n",line4);


printf("gender:");
gets(line5);
fprintf(f,"gender:%s\n\n",line5);


printf("Email Address:");
gets(line6);
fprintf(f,"Email Address:%s\n\n",line6);
fclose(f);

printf("PASSWORD:");
scanf("%s",pass);
f=(fopen(pass,"a"));
fclose(f);

ret:
printf("\n\nJust a couple more details...\n Type the code shown\n\n");
printf("do not input character!\n\n");
printf(" __________________\n");
printf("| |\n");
printf("| 2253028 |\n");
printf("|__________________|\n\n");


printf("type the codes:");
scanf("%d",&code);
///3
switch (code)

{
///3
case 2253028:
printf("\n\nsuccessfully signed\n\n");
system("pause");
goto alog;
///3
case 2:
printf("error");
system("cls");
goto ret;
///3
default:
system("cls");
goto ret;
}
alog:
system("cls");
for (m=0;m<=44;m++) printf("%d",m); printf("\n\n\n\n\n\n\n\n\n\n\n\t\t\t\tlog-in?[y/n]:"); scanf("%s",&log); ///4 switch (log) { ///4 case 'y': { final: system("cls"); printf("enter ID:"); scanf("%s",fid); printf("enter PASSWORD:"); scanf("%s",fpass); ///5 if ((strcmp(fid,filename)==0)&&(strcmp(fpass,pass)==0)) { main: system("cls"); printf("\n\n\n\n\n view account[1]\n\n"); printf("military time [2]\n\n"); printf("log-out [3]\n\n\n\n\n"); printf("enter your choice:"); scanf("%d",&choice); switch (choice) { case 1: { system("cls"); f=(fopen(filename,"r")); fgets(line1,20,f); fgets(line2,20,f); fgets(line3,20,f); fgets(line4,20,f); fgets(line5,20,f); fgets(line6,20,f); printf("your account:\n\n"); puts(line1); puts(line2); puts(line3); puts(line4); puts(line5); puts(line6); system("pause"); goto main; break; } case 2: { system("cls"); printf("enter your name:"); scanf("%s",z); printf("hello %s have fun! enjoy...\n\n",z); printf("enter your military time:"); scanf("%d",&x); /*ACAS ARNEL M.*/ if(x==1300) { printf("1:00 pm"); system("cls"); system("pause"); goto main; } if((x>=1301)&&(x<=1399)) { c=x-1300; printf("1:%dpm",c); system("pause"); goto main; } if(x==1400) { printf("2:00 pm"); system("pause"); goto main; } if((x>=1401)&&(x<=1499)) { c=x-1400; printf("2:%d pm",c); system("pause"); goto main; } if(x==1500) { printf("3:00 pm"); system("pause"); goto main; } if((x>=1501)&&(x<=1599)) { c=x-1500; printf("3:%d pm",c); system("pause"); goto main; } if(x==1600) { printf("4:00 pm"); system("pause"); goto main; } if((x>=1601)&&(x<=1699)) { c=x-1600; printf("4:%d pm",c); system("pause"); goto main; } if(x==1700) { printf("5:00 pm"); system("pause"); goto main; } if((x>=1701)&&(x<=1799)) { c=x-1700; printf("5:%d pm",c); system("pause"); goto main; } if(x==1800) { printf("6:00 pm"); system("pause"); goto main; } if((x>=1801)&&(x<=1899)) { c=x-1800; printf("6:%d pm",c); system("pause"); goto main; } if(x==1900) { printf("7:00 pm"); system("pause"); goto main; } if((x>=1901)&&(x<=1999)) { c=x-1900; printf("7:%d pm",c); system("pause"); goto main; } if(x==2000) { printf("8:00"); system("pause"); goto main; } if((x>=2001)&&(x<=2099)) { c=x-2000; printf("8:%d pm",c); system("pause"); goto main; } if(x==2100) { printf("9:00 pm"); system("pause"); goto main; } if((x>=2101)&&(x<=2199)) { c=x-2100; printf("9:%d pm",c); system("pause"); goto main; } if(x==2200) { printf("10:00 pm"); system("pause"); goto main; } if((x>=2201)&&(x<=2299)) { c=x-2200; printf("10:%d pm",c); system("pause"); goto main; } if(x==2300) { printf("11:00 pm"); system("pause"); goto main; } if((x>=2301)&&(x<=2399)) { c=x-2300; printf("11:%d pm"); system("pause"); goto main; } if(x==2400) { printf("12:00 pm"); system("pause"); goto main; } if((x>=2401)&&(x<=2499)) { c=x-2400; printf("12:%d pm",c); system("pause"); goto main; } if(x==100) { printf("1:00 am"); system("pause"); goto main; } if((x>=101)&&(x<=199)) { c=x-100; printf("1:%d am",c); system("pause"); goto main; } if(x==200) { printf("2:00 am"); system("pause"); goto main; } if((x>=201)&&(x<=299)) { c=x-200; printf("2:%d am",c); system("pause"); goto main; } if(x==300) { printf("3:00 am"); system("pause"); goto main; } if((x>=301)&&(x<=399)) { c=x-300; printf("3:%d am",c); system("pause"); goto main; } if(x==400) { printf("4:00 am"); system("pause"); goto main; } if((x>=401)&&(x<=499)) { c=x-400; printf("4:%d am",c); system("pause"); goto main; } if(x==500) { printf("5:00 am"); system("pause"); goto main; } if((x>=501)&&(x<=599)) { c=x-500; printf("5:%d am",c); system("pause"); goto main; } if(x==600) { printf("6:00 am"); system("pause"); goto main; } if((x>=601)&&(x<=699)) { c=x-600; printf("6:%d am",c); system("pause"); goto main; } if(x==700) { printf("7:00 am"); system("pause"); goto main; } if((x>=701)&&(x<=799)) { c=x-700; printf("7:%d am",c); system("pause"); goto main; } if(x==800) { printf("8:00 am"); system("pause"); goto main; } if((x>=801)&&(x<=899)) { c=x-800; printf("8:%d am",c); system("pause"); goto main; } if(x==900) { printf("9:00 am"); system("pause"); goto main; } if((x>=901)&&(x<=999)) { c=x-900; printf("9:%d am",c); system("pause"); goto main; } if(x==1000) { printf("10:00 pm"); system("pause"); goto main; } if((x>=1001)&&(x<=1099)) { c=x-1000; printf("10:%d am"); system("pause"); goto main; } if(x==1100) { printf("11:00 am"); system("pause"); goto main; } if((x>=1101)&&(x<=1199)) { c=x-1100; printf("11:%d am",c); system("pause"); goto main; } if(x==1200) { printf("12:00 pm"); system("pause"); goto main; } if((x>=1201)&&(x<=1299))
{
c=x-1200;
printf("12:%d pm",c);
system("pause");
goto main;
}
else
{
printf("error input! guys....\n\n\n\n");
system("pause");
goto main;
return 0;
}


goto main;
}
case 3:
{
system("cls");
printf("\n\n\nsuccessfully log-out!");

return 0;
}
default:
{
goto main;
}
}














}
///5
else
{
system("cls");
printf("user no register!\n\n");
goto final;
}

break;
}
///4
case 'n':
{
printf("bye bye.... see you soon!");
break;
}
///4
default:
{
goto alog;
}

}






















//f=(fopen("password.txt","w"));
// printf("PASSWORD:");
// scanf("%s",filename);
// fclose(f);



// f=(fopen(filename,"r"));
// fgets(line,500,f);
// printf("the line you enter:");
// puts(line);

break;
}
}
}
return 0;
}

Random Number in C Language

#include
#include
#include
int x,y[5],i,temp,k;

int main(void)

{

srand(time(NULL));
for (i=1;i<=5;i++)
{

printf("%d\n",x=rand()%10);
y[i]=x;
}

printf("\n\n");

for (i=1;i<=5;i++)
{

for (k=i;k<=5;k++)

{
if (y[i]>y[k])

{
temp=y[i];
y[i]=y[k];
y[k]=temp;
}
}


}
for (i=1;i<=5;i++)
{
printf("%d\n",y[i]);

}






return(0);
}

Fractions in C Language

#include

int factor (int num)

{

if (num>1)

{

return (num * factor(num-1));

}

else{}

return (1);

}

int main(void)

{

int firstnum,secnum,permdin,permfact,sub1;

printf("Enter First Number:");

scanf("%d",&firstnum);

printf("%d = %d \n\n\n",firstnum,factor(firstnum));

printf("Enter Second Number:");

scanf("%d",&secnum);

printf("%d = %d \n\n\n",secnum,factor(secnum));

if(firstnum>secnum)

{

sub1=firstnum-secnum;

permdin=factor(sub1);

permfact=(factor(firstnum)/permdin);

printf("Permutation = %d\n\n\n",permfact);

printf( "Combination : %d\n\n\n",factor(firstnum) / (factor(secnum)* factor(firstnum-secnum)));

printf("\n\n\n");

}

else

{

printf("Invalid:\n\n\n");

}

return 0;

}

Multiplication Table in C Language

#include

int main()
{
//char ans;
int column,row,i,j;
printf("rows:");
scanf("%d",&row);
printf("column:");
scanf("%d",&column);
i=0;
while(i
{
j=0;
printf("%d\t",(i+1));
while(j
{
printf("%d\t",(i+1)*(j+1));
j++;
}
printf("\n");
i++;
}
return 0;
}

Create a File in C language

#include
#include
#include
int main()
{
FILE *f;
char filename[20];
char line[100];

int returnvar=1;


while(returnvar==1)
{
printf("Enter Filename:");
//scanf("%s",filename);
gets(filename);

if((f=fopen(filename,"r"))!=NULL)
{
printf("ERROR! FILE NAA NA!!\n");
returnvar=1;
}
else if((f=fopen(filename,"w"))==NULL)
{
printf("ERROR CREATING FILE\n");
returnvar=1;
}
else
{
printf("FILE CREATED\n");
f=fopen(filename,"w");
printf("Write a line Please:");
gets(line);
fprintf(f,"%s",line);

//pFile = fopen ("myfile.txt" , "r");
f=fopen(filename,"r");
fgets (line , 100 , f);
// printf("ang sulat sa file:");
puts(line);

// puts("\n\nThe line you entered is/are: [ %s ]\n",line);



break;
}
}
fclose(f);
return 0;

}

Convert to Binary

#include
using namespace std;
#include
#include

char *entry, letter, choice[2];
int ascii, len, binary[8], total;
void prog();

int main()
{
prog();
return 0;
}

void prog()
{
entry = new char[501];
/* entry should be dynamic, otherwise a new
string entry of 501 chars would be created
each time function is called!
Talk about memory hog! */
cout<<"Enter string to convert (up to 500 chars): "; cin.getline(entry, 500); len = strlen(entry); /* get the number of characters in entry. */ /* this loop is executed for each letter in the string. */ for(int i = 0; i0) /* This while loop converts the ASCII # into binary,
stores it backwards into the binary array. */
{
/* To get the binary code one must take the decimal number in
question, take it and divide it by two repeatedly, save
the remainder (which will become the binary number), save
the whole number, divide by two, and repeat the whole
process until 0 is reached. This if-else statement serves
this functionality, by getting the remainder of the ascii
code, storing it in the array and then dividing the int
ascii by two */
if((ascii%2)==0)
{
binary[total] = 0;
ascii = ascii/2;
total++; /* increasing by one each time will yeild the
number of numbers in the array. */
}
else
{
binary[total] = 1;
ascii = ascii/2;
total++;
}
}
total--; /* due to data type factors, the program will actually
add a 0 at the end of the array that is not supposed
to be there, decrementing total will solve this
problem, as that 0 will not be displayed. */
/* this while loop displays the binary code for that letter. */
while(total>=0)
{
cout<
total--;
}
}
delete[] entry; /* free up the memory used by entry */
cout<<<"Do again(1 = yes, 2= no)?: ";
cin.getline(choice,3);
if(choice[0] == '1')
prog(); /* program is recursive, it calls itself. It's kinda
like a function loop of sorts. */
else
exit(0); /* quits the program */
}