Are C and Pascal really that different?
I'm learning Pascal at college and decided that it would be interesting to see how much like Pascal I could get C to look like. Well....
Code:
#include "pascal.h"
program
begin
STRING text[81];
writeln ("Hello how are you?");
writeln ("Enter you name:");
readln (text);
write ("Hello ");
writeln (text);
finish
end
Easy with a the help of a few #defines and function declarations from pascal.h:
Code:
#define program int main (void)
#define begin {
#define end }
#define finish return 0;
typedef char STRING;
extern void writeln (const char * str);
extern void readln (char * str);
extern char read (void);
extern void write (const char * str);
And here are the functions: (in a separate source file of course)
Code:
#include <stdio.h>
void writeln (const char * str)
{
puts (str);
}
void readln (char * str)
{
gets (str);
}
void write (const char * str)
{
printf (str);
}
char read (void)
{
return getchar ();
}
So what do you think? Can anyone make it look a little more convincing?