void io_display(const char *str, int row, int col, int len)
{
int i = 0;
len <= 0 ? io_move(row, col) && io_putstr(str) : io_move(row, col) && while(io_putch(str[i++])) && putch(' ');
}
Sunday, September 27, 2009
Monday, September 21, 2009
OOP344 Challenge - Leaner and Meaner
/*
* GetInt.c
*
* Created by Ljubomir Gorscak
* 21/09/09.
* Seneca Learn Id : gljubomir
* OOP344 - Fall 2009
*
* Challenge: write this function without
* using any library functions;
* void GetInt(char *strint, int val);
* this function gets an integer value and
* converts it to a string ("strint")
*
* My lean and mean version has lots of
* notes but very little code. I include
* a main()and two additional functions
* for display.
*
* I changed the brackets so that the code
* will be easier to read on this blog.
*/
#include
#define MAX 6
void GetInt(char *, int);
void PrintStrint(const char *);
void PrintMAX();
int main()
{
int val;
char strint[MAX];
printf("Enter an integer less than ");
PrintMAX();
scanf("%d", &val);
printf("Your integer is: %d\n", val);
GetInt(strint, val);
strint[MAX] = '\0';
printf("The string version is: ");
PrintStrint(strint);
return 0;
} /* end of main */
/* this function gets an integer value
* and converts it to a string ("strint")
*/
void GetInt(char *strint, int val)
{
int i;
int mod_int;
mod_int = val % 10;
val /= 10;
for (i = MAX - 1; i >= 0; i--)
{
strint[i] = mod_int + 48;
mod_int = val % 10;
val /= 10;
}
} /* end of GetInt(...) */
/* this function is used to print the string
* version of the number without the leading
* zeros
*/
void PrintStrint(const char *strint)
{
int i = 0;
for ( ; i < MAX; i++)
{
if(i < MAX && strint[i] != '0')
for ( ; i < MAX && printf("%c", strint[i]); i++);
}
printf("\n");
} /* end of PrintStrint(...) */
/* this function is used to inform the user
* about the value of #define MAX so that
* the user does not exceed MAX input
*/
void PrintMAX()
{
int i = 0;
for ( ; i < MAX && printf("9"); i++);
printf(": ");
} /* end of PrintMAX() */
/*
* end
*/
* GetInt.c
*
* Created by Ljubomir Gorscak
* 21/09/09.
* Seneca Learn Id : gljubomir
* OOP344 - Fall 2009
*
* Challenge: write this function without
* using any library functions;
* void GetInt(char *strint, int val);
* this function gets an integer value and
* converts it to a string ("strint")
*
* My lean and mean version has lots of
* notes but very little code. I include
* a main()and two additional functions
* for display.
*
* I changed the brackets so that the code
* will be easier to read on this blog.
*/
#include
#define MAX 6
void GetInt(char *, int);
void PrintStrint(const char *);
void PrintMAX();
int main()
{
int val;
char strint[MAX];
printf("Enter an integer less than ");
PrintMAX();
scanf("%d", &val);
printf("Your integer is: %d\n", val);
GetInt(strint, val);
strint[MAX] = '\0';
printf("The string version is: ");
PrintStrint(strint);
return 0;
} /* end of main */
/* this function gets an integer value
* and converts it to a string ("strint")
*/
void GetInt(char *strint, int val)
{
int i;
int mod_int;
mod_int = val % 10;
val /= 10;
for (i = MAX - 1; i >= 0; i--)
{
strint[i] = mod_int + 48;
mod_int = val % 10;
val /= 10;
}
} /* end of GetInt(...) */
/* this function is used to print the string
* version of the number without the leading
* zeros
*/
void PrintStrint(const char *strint)
{
int i = 0;
for ( ; i < MAX; i++)
{
if(i < MAX && strint[i] != '0')
for ( ; i < MAX && printf("%c", strint[i]); i++);
}
printf("\n");
} /* end of PrintStrint(...) */
/* this function is used to inform the user
* about the value of #define MAX so that
* the user does not exceed MAX input
*/
void PrintMAX()
{
int i = 0;
for ( ; i < MAX && printf("9"); i++);
printf(": ");
} /* end of PrintMAX() */
/*
* end
*/
Sunday, September 20, 2009
OOP344 Challenge - Answer
/*
* GetInt.c
*
* Created by Ljubomir Gorscak on 20/09/09.
* Seneca Learn Id : gljubomir
* OOP344 - Fall 2009
*
* Challenge: write this function without using
* any library functions;
* void GetInt(char *strint, int val);
* this function gets an integer value and
* converts it to a string ("strint")
*
*/
#include
void GetInt(char *, int);
int main(){
int val;
char strint[6];
printf("Enter an integer less than 999999: ");
scanf("%d", &val);
printf("Your integer is: %d\n", val);
GetInt(strint, val);
strint[6] = '\0';
printf("The string version is: %s\n", strint);
return 0;
}
/* this function gets an integer value
* and converts it to a string ("strint")
*/
void GetInt(char *strint, int val){
int mod_int = val % 10;
int temp_int = val / 10;
int i;
for (i = 6 - 1; i >= 0; i--){
strint[i] = mod_int + 48;
mod_int = temp_int % 10;
temp_int /= 10;
}
}
/*
* end
*/
* GetInt.c
*
* Created by Ljubomir Gorscak on 20/09/09.
* Seneca Learn Id : gljubomir
* OOP344 - Fall 2009
*
* Challenge: write this function without using
* any library functions;
* void GetInt(char *strint, int val);
* this function gets an integer value and
* converts it to a string ("strint")
*
*/
#include
void GetInt(char *, int);
int main(){
int val;
char strint[6];
printf("Enter an integer less than 999999: ");
scanf("%d", &val);
printf("Your integer is: %d\n", val);
GetInt(strint, val);
strint[6] = '\0';
printf("The string version is: %s\n", strint);
return 0;
}
/* this function gets an integer value
* and converts it to a string ("strint")
*/
void GetInt(char *strint, int val){
int mod_int = val % 10;
int temp_int = val / 10;
int i;
for (i = 6 - 1; i >= 0; i--){
strint[i] = mod_int + 48;
mod_int = temp_int % 10;
temp_int /= 10;
}
}
/*
* end
*/
Thursday, September 17, 2009
A shout out to my peeps in OOP344!
This is my first blog. Future blogs will probably have something to do with C/C++ programming.
Subscribe to:
Posts (Atom)
