Similar Threads:
1.catching multiple $SIG{INT}
hi,
in the beginning of the script, i open and read from a large text
file. i want to make this uninterruptable in order to prevent data
corruption if someone types ctrl-c.
i do this in the read subroutine by:
local $SIG{INT} = "IGNORE";
this works if the person only hits ctrl-c ONCE, but the ctrl-c is
executed immediately if the signal is sent again (i do reset the
signal to DEFAULT after the file is closed).
so my questions is:
how can perl trap multiple signals, interrupt in particular?
i am working with 2000+ lines of code with a lot of modules.
i'm grateful for any help!
_kati wilson
2.Why char** dynamic_string_array(int ROWS, int SIZE) doesn't work properly?
Hi,please help...
It works fine when I define a 2-D array like char code[ROWS][SIZE].
But it won't work when I try to define the array dynamically using a
function. It just crashes.
Does anyone know why?
The compiler i'm using is Dev c++.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int file_length(FILE *file);
void down_string(char *p);
char* issubstring(char *str1,char *str2);
char** dynamic_string_array(int ROWS, int SIZE);
int main(void)
{
int row,n,i,coursefound=0,ROWS,SIZE,test;
FILE *datafile;
datafile=fopen("3rdyear.csv", "rb");
ROWS=file_length(datafile);
printf("Has %d lines\n",ROWS);
char **Code,**Course,**ClassSize,**Time1,**Time2,**Room,c;
char search[30];
Code=dynamic_string_array(ROWS,SIZE);
Course=dynamic_string_array(ROWS,SIZE);
ClassSize=dynamic_string_array(ROWS,SIZE);
Time1=dynamic_string_array(ROWS,SIZE);
Time2=dynamic_string_array(ROWS,SIZE);
Room=dynamic_string_array(ROWS,SIZE);
for (row=0; row <ROWS; row++) {
test=fscanf(datafile, "%[^,],%[^,],%[^,],%[^,],%[^,],%[^\n]\n",
Code[row],Course[row],ClassSize[row],
Time1[row],Time2[row],Room[row]);
printf("row=%d,scanf converted %d (%s,%s,%s,%s,%s,%s)\n",
row, test,
Code[row],Course[row],ClassSize[row],Time1[row],Time2[row],Room[row]);
}
printf("Please enter a name\n>");
scanf("%s",search);
for(i=1; i<ROWS; i++) {
if(issubstring(Course[i],search)) {
coursefound=1;
printf("Course %s found!!\nTime 1 is %s\nTime2 is
%s\nVenue:%s",Course[i],Time1[i],Time2[i],Room[i]);
}
}
if(coursefound==0) printf("No such Course!.\n");
fclose(datafile);
return EXIT_SUCCESS;
}
void down_string(char *p) //turns uppercase letters in a string to
lowercase
{
int i;
for(i=0;p[i]!='\0';i++)
{
if((p[i]>='A')&&(p[i]<='Z')) p[i]+=32;
}
}
char* issubstring(char *str1,char *str2) //checks if string2 is a
substring of string2
{
char tmp1[30],tmp2[30];
strcpy(tmp1, str1);
strcpy(tmp2, str2);
down_string(tmp1); //turn it to lowercase
down_string(tmp2);
return (strstr(tmp1, tmp2));
}
char** dynamic_string_array(int ROWS, int SIZE)
{
char **array;
int i;
array=(char**) malloc(ROWS*sizeof(char));
for(i=0;i<ROWS;i++)
array[i]=(char *) malloc(SIZE*sizeof(char));
return array;
}
int file_length(FILE *file)
{
int lines;
char dummy[100];
rewind(file);
lines=0;
while( fgets(dummy, 100, file) != NULL)
lines++;
rewind(file);
return(lines);
}
3.will Hyperlinks work on a CD when created from files stored on Int
relative addressing,(\subdirectory\subdirectory\file.nam) or put them in
the same folder (file.nam)
mgrady wrote:
> How do you create a hyperlink in (ppt / word) that links to another file and
> document, when all of the final documents will be stored and accessed from a
> CD?
>
>
>
>
4.pass int* to perl
Hello,
I need to call perl from c.
To pass an integer, I use to make a newSViv.
How do I do to pass a int* ?
Should I just cast the int* to int ans passed as an SV ?
in perl I need to get the value by $$var.
Thank.
--
---
==========================================================================
Patrick DUPR | |
Department of Chemistry | | Phone: (44)-(0)-1904-434384
The University of York | | Fax: (44)-(0)-1904-432516
Heslington | |
York YO10 5DD United Kingdom | | email: XXXX@XXXXX.COM
==========================================================================
5.signal processing INT or TERM
perl 5.8.2
OS: AIX fully POSIX compliant
my script moves files from one dir to another.
When I want my script to stop, should I pass it along the signal INT
or TERM?
INT just interrupts the script. It finishes whatever it's processing
and then it's done.
TERM on the other hand, just sends a TERMination signal, waits a few
seconds, then KILLs the program. TERM is more common I guess when
starting/stopping unix shell scripts in the init dir.
My fear is that if I pass the TERM signal, maybe the system will chop
off the files that are being moved on the fly. The "few seconds" are
unpredictable in value at least on my system. So the system might say
'it's been too long, let's kill it."
Any thoughts? Is there a "perlish" way to do it?
6. packing int to hex
7. maximum int value
8. Storing a long value in an int