27. January 2012 17:36
The following example will check for a palindrom in C. You know one of thoose words spelt the same forwards as backwards. The smart part of this program is the edge case where you have an odd number of letters in the string. Well actually this can simply be ignored since there is no point in comparing the middle charecter to its self.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int try(char *str) {
int len = strlen(str);
int i;
for(i =0;i<len/2;i++)
if (str[i] != str[len - 1 - i])
return 0;
return 1;
}
int main(int argc, char**argv) {
char *s1 = "ffoof";
char *s2 = "foof";
char *s3 = "fooof";
if (try(s1))
printf("%s\n", s1);
if (try(s2))
printf("%s\n", s2);
if (try(s3))
printf("%s\n", s3);
return 0;
}
0648ded8-4798-4248-a473-b8e1da1830e2|0|.0
27. January 2012 08:00
On a old decstation 3100 I was deleting last semesters users to try to dig up some disk space, I also deleted some test users at the same time.
One user took longer then usual, so I hit control-c and tried ls.
"ls: command not found"
Turns out that the test user had / as the home directory and the remove user script in ultrix just happily blew away the whole disk. ftp, telnet, rcp, rsh, etc were all gone. Had to go to tapes, and had one LONG rebuild of X11R5.
09a84687-db47-4f1e-84f3-8a683eb7bf60|0|.0
26. January 2012 08:00
A short code example of using popen in c to start a process then write to it using fprintf.
#include <stdio.h>
int main(int argc, char **argv) {
FILE *fp = popen("cat", "w");
int i = 0;
for(i=0;i<10;i++)
fprintf(fp, "Count = %d\n", i);
pclose(fp);
return 0;
}
4a32ce2e-f20f-4a87-ab4c-4ffba8fac758|0|.0
25. January 2012 19:48
I fix some issues and created some new goodies to play with.
14c92d71-1f8e-4e4b-9607-6673d51678ba|0|.0
20. January 2012 12:37
Well, we had one system on which you couldn't log in on the console for a while after rebooting, but it'd start working sometimes. What was happening was that the manufacturer had, for some idiot reason, hardcoded the names of the terminals they wanted to support into getty (this manufacturers own terminals, that I can understand, but also a handful of common types like adm3a) so getty could clear the screen properly (I guess hacking that into gettydefs was too obvious or something). If getty couldn't recognise the terminal type on the command line, it'd display a message on the console reading "Unknown terminal type pc100". We ignored this flamage, which was a pity. Cos that was the problem.
It did this *before* opening the terminal, so if it happened to run between the time rc completed and the getty on the console started the console got attached to some random terminal somewhere, so when login attempted to open /dev/tty to prompt for a password it failed.
Moral: always deal with error messages even when you *know* they're bogus.
Moral: never cry wolf.
2d47f202-abcc-4434-887e-eadb8cae9975|0|.0