Search Results

Search found 1848 results on 74 pages for 'printf'.

Page 52/74 | < Previous Page | 48 49 50 51 52 53 54 55 56 57 58 59  | Next Page >

  • Why is there so much "magic" in Perl?

    - by eugene y
    I'm looking through perlop and perlsub pages of the Perl manual. There are many references about "magic" and "magical" here (just search any of them for the "magic"). I wonder why is Perl so rich in them. Some examples: print ++($foo = 'zz') # prints 'aaa' printf "%d: %s", $! = 1, $! # prints '1: Operation not permitted' use warnings; my $i; print $i++ # no warning for uninitialized value while (my $line = <FH>) { ... } # $line is actually tested for definedness

    Read the article

  • Better way to write this regex to match multi-ordered property list?

    - by Andrew Philips
    I've been whacking on this regex for a while, trying to build something that can pick out multiple ordered property values (DTSTART, DTEND, SUMMARY) from an .ics file. I have other options (like reading one line at a time and scanning), but wanted to build a single regex that can handle the whole thing. SAMPLE PERL # There has got to be a better way... my $x1 = '(?:^DTSTART[^\:]*:(?<dts>.*?)$)'; my $x2 = '(?:^DTEND[^\:]*:(?<dte>.*?)$)'; my $x3 = '(?:^SUMMARY[^\:]*:(?<dtn>.*?)$)'; my $fmt = "$x1.*$x2.*$x3|$x1.*$x3.*$x2|$x2.*$x1.*$x3|$x2.*$x3.*$x1|$x3.*$x1.*$x2|$x3.*$x2.*$x1"; if ($evts[1] =~ /$fmt/smo) { printf "lines:\n==>\n%s\n==>\n%s\n==>\n%s\n", $+{dts}, $+{dte}, $+{dtn}; } else { print "Failed.\n"; } SAMPLE DATA BEGIN:VEVENT UID:0A5ECBC3-CAFB-4CCE-91E3-247DF6C6652A TRANSP:OPAQUE SUMMARY:Gandalf_flinger1 DTEND:20071127T170005 DTSTART,lang=en_us:20071127T103000 DTSTAMP:20100325T003424Z X-APPLE-EWS-BUSYSTATUS:BUSY SEQUENCE:0 END:VEVENT SAMPLE OUTPUT lines: == 20071127T103000 == 20071127T170005 == Gandalf_flinger1

    Read the article

  • runtime error (SIGSEGV)

    - by vamsi2018
    hi, i would be happy to know why i got this error for the problem http://www.codechef.com/problems/AXR1P2 in codechef.com and my code is... include include int main() { int *num=0,n=0,i=0,max=0;char *s=""; int sum[9]={1,5,14,20,25,31,32,38,39},dsum[9]={1,7,8,14,19,25,26,32,33},unitdig=0; do { gets(s); *(num+i)=(int)atoi(s); i++; }while(s!='#'); max=i; for(i=0;i10) unitdig=33(n/10-1)+39+dsum[(n%10)-1]; else unitdig=sum[(n%10)-1]; printf("%d\n",unitdig%10); } getchar(); return 0;}

    Read the article

  • C SIGSEGV Handler & Mprotect

    - by pws5068
    I'm constructing a program which uses mprotect() to restrict a block of memory from accessing. When the memory is requested, a SIGSEGV is thrown which I listen for using a signal() call. Once the SIGSEGV has been detected, I need to somehow access the pointer to the memory that was requested (that threw the fault) and the size of the segment requested. Is this possible? void fifoSigHandler(){ // Needs to only remove protection from requested block of virtual memory mprotect(fifoVm,(size_t)fifoVm_size,PROT_WRITE); printf("Caught Seg Fault"); } void fifo_init(void* vm, int vm_size, int n_frames, int page_size) { fifoVm = vm; fifoVm_size = vm_size; fifoFrames = n_frames; fifoPageSize = page_size; mprotect(fifoVm,(size_t)fifoVm_size,PROT_NONE); signal(SIGSEGV, fifoSigHandler); } Additionally, is there a way to determine the level of mprotect() a block of memory is currently assigned (PROT_NONE,PROT_READ, etc..)?

    Read the article

  • gcc does not generate debugger info when using -g, -ggdb, -g3, or -ggdb3

    - by CJJ
    I'm using GCC 4.4.1 and GDB 7.0-ubuntu on Ubuntu 9.10. However, GCC won't generate debugger info when using any of the following switches: -g, -g3, -ggdb, or -ggdb3. So when I run the program with GDB, its as if there was no debugger information generated. I have created very simple test source files in a new, empty folder. Here is one example: #include <stdlib.h> #include <stdio.h> int main (int argc, char **argv) { char msg[4]; // allocate 4 bytes on the stack strcpy (msg, "hello world"); // overflow printf ("%s\n", msg); return 0; }

    Read the article

  • random numbers in C

    - by Sergey
    for(i = 0; i < n; i++){ srand(time(NULL)); printf("%d ", time(NULL)); for(j = 0; j < (n-1); j++){ a[i,j] = rand(); } } I try to generate random numbers, but they are the same... I try srand(i * time(NULL)). No matter.. What should i do?

    Read the article

  • array iteration strstr in c

    - by lex0273
    I was wondering if it's safe to do the following iteration to find the first occurrence of str within the array or if there is a better way. Thanks #include <stdio.h> #include <string.h> const char * list[] = {"One","Two","Three","Four","Five"}; char *c(char * str) { int i; for (i = 0; i < 5; i++) { if (strstr(str, list[i]) != NULL) return list[i]; } return "Not Found"; } int main() { char str[] = "This is a simple string of hshhs wo a char"; printf("%s", c(str)); return 0; }

    Read the article

  • How to append strings using sprintf ?

    - by rejinacm
    Hey everybody, Thank you all before I start. I am facing a serious issue with sprintf. suppose my code snippet is : sprintf(Buffer,"Hello World"); sprintf(Buffer,"Good Morning"); sprintf(Buffer,"Good Afternoon"); . . . Some hundred sprints.... If i do like this, its getting overwritten. How can I avoid overwritting using sprintf. If i give a printf at the end i want to see all the lines. How to xchieve this.

    Read the article

  • Bing search api . colon in xml

    - by nicky
    i am trying to parse bing search xml but whenever i try to access xml element there is colon in every elemet which gives error Parse error: syntax error, unexpected ':' in / here is my php code foreach($searchresponse->web:Web->web:Results as $result) { printf(" \n%s", $result->web:Description); } here is bing xml response <SearchResponse Version="2.2"> - <Query> <SearchTerms>ipl</SearchTerms> </Query> - <web:Web> <web:Total>2430000</web:Total> <web:Offset>0</web:Offset> - <web:Results> - <web:WebResult> <web:Title>Indian Premier League | IPLT20</web:Title> what is the meaning of colon in xml tags.

    Read the article

  • recv returns old data

    - by anon
    This loop is supposed to take data from a socket line by line and put it in a buffer. For some reason, when there is no new data to return, recv returns the last couple lines it got. I was able to stop the bug by commenting out the first recv, but then I cant tell how long the next line will be. I know it's not a while(this->connected){ memset(buf, '\0', sizeof(buf)); recv(this->sock, buf, sizeof(buf), MSG_PEEK); //get length of next message ptr = strstr(buf, "\r\n"); if (ptr == NULL) continue; err = recv(this->sock, buf, (ptr-buf), NULL); //get next message printf("--%db\n%s\n", err, buf); tok[0] = strtok(buf, " "); for(i=1;tok[i-1]!=NULL;i++) tok[i] = strtok(NULL, " "); //do more stuff }

    Read the article

  • IOKit header assert.h gone? [answered]

    - by Julian Kessel
    I want to get the hardware address of my mac's ethernet card. In all samples I saw in include on IOKit/assert.h . Which doesn't seem to exist on my system. GCC throws an error saying he doesn't know the type IOEthernetAddress. Is assert.h necessary for my task? It would be great if someone coud give me a working sample. [edit] here's my code, think this will help understanding the problem: #include <IOKit/assert.h> #include <IOKit/network/IOEthernetController.h> #include <IOKit/network/IOEthernetInterface.h> int main(){ IOEthernetAddress addr; getHardwareAddress(&addr); printf("%x", addr); return 0; }

    Read the article

  • mysqli prepared statements select *

    - by Victor Dallecio
    I've spent this sunday trying to find what is wrong to the following code as it is not counting the rows. Could somebody help me with it? Thanks! /*check if same IP has visited today*/ if ($stmt = $mysqli->query('SELECT * FROM table WHERE colum1 = ? AND colum2 > DATE_SUB(NOW(), INTERVAL 1 DAY)')) { $stmt->bind_param('s', $ip); /* execute query */ $stmt->execute(); /*number of rows */ /*store result when using prepared statements*/ $stmt->store_result(); $row_cnt = $stmt->num_rows; printf("Result set has %d rows.\n", $row_cnt); $stmt->close(); }

    Read the article

  • Hex to Decimal conversion in C

    - by darkie15
    Hi All, Here is my code which is doing the conversion from hex to decimal. The hex values are stored in a unsigned char array: int liIndex ; long hexToDec ; unsigned char length[4]; for (liIndex = 0; liIndex < 4 ; liIndex++) { length[liIndex]= (unsigned char) *content; printf("\n Hex value is %.2x", length[liIndex]); content++; } hexToDec = strtol(length, NULL, 16); Each array element contains 1 byte of information and I have read 4 bytes. When I execute it, here is the output that I get : Hex value is 00 Hex value is 00 Hex value is 00 Hex value is 01 Chunk length is 0 Can any one please help me understand the error here. Th decimal value should have come out as 1 instead of 0. Regards, darkie

    Read the article

  • how to flush the console buffer?

    - by DoronS
    Hi all, i have some code that run repetedly : printf("do you want to continue? Y/N: \n"); keepplaying = getchar(); in the next my code is running it doesnt wait for input. i found out that getchar in the seconed time use '\n' as the charcter. im gussing this is due to some buffer the sdio has, so it save the last input which was "Y\n" or "N\n". my Q is, how do i flush the buffer before using the getchar, which will make getchar wait for my answer?

    Read the article

  • How does 64 bit code work on OS-X 10.5?

    - by philcolbourn
    I initially thought that 64 bit instructions would not work on OS-X 10.5. I wrote a little test program and compiled it with GCC -m64. I used long long for my 64 bit integers. The assembly instructions used look like they are 64 bit. eg. imultq and movq 8(%rbp),%rax. I seems to work. I am only using printf to display the 64 bit values using %lld. Is this the expected behaviour? Are there any gotcha's that would cause this to fail? Am I allowed to ask multiple questions in a question? Does this work on other OS's?

    Read the article

  • Calling C function from DTrace scripts

    - by dmeister
    DTrace is impressive, powerful tracing system originally from Solaris, but it is ported to FreeBSD and Mac OSX. DTrace uses a high-level language called D not unlike AWK or C. Here is an example: io:::start /pid == $1/ { printf("file %s offset %d size %d block %llu\n", args[2]->fi_pathname, args[2]->fi_offset, args[0]->b_bcount, args[0]->b_blkno); } Using the command line sudo dtrace -q -s <name>.d <pid> all IOs originated from that process are logged. My question is if and how it is possible to call custom C functions from a DTrace script to do advanced operations with that tracing data during the tracing itself.

    Read the article

  • How to properly siglongjmp out of signal handler?

    - by EpsilonVector
    Suppose I have the following code: In order to implement a context switch I activate ualarm and when it jumps to the handler it setjmp's the current context, and longjmps to the next, expecting to eventually return to the alarm handler and longjmped back into this context (the contexts are cycled through in a Round Robin). For this I need to keep SIGALRM unblocked in between alarm_handlers. I came up with the following code, which doesn't seem to work. What's wrong with it and what is the right way to do this? void alarm_handler(){ if(sigsetjmp(toc->threads[toc->RR_pointer].env, 0)){ ualarm(200, 0); signal(SIGALRM, alarm_handler); return; } get_next_context_number(toc->RR_pointer); //is a macro for (j=0; j<10; j++) printf("ALARM HANDLER\n"); siglongjmp(toc->threads[toc->RR_pointer].env, 1); }

    Read the article

  • Whats the problem with int *p; *p=23;

    - by piemesons
    Yesterday in my interview I was asked this question. (At that time I was highly pressurized by so many abrupt questions). int *p; *p=23; printf('%d',*p); Is there any problem with this code? I explained him that you are trying to assign value to a pointer to whom memory is not allocated. But the way he reacted, it was like I am wrong. Although I got the job but after that he said Mohit think about this question again. I don't know what he was trying to say. Please let me know is there any problem in my answer?

    Read the article

  • Why does gcc add symbols to non-debug build?

    - by Matt Holgate
    When I do a release build with gcc (i.e. I do not specify -g), I still seem to end up with symbols in the binary, and have to use strip to remove them. In fact, I can still breakpoint functions and get backtraces in gdb (albeit without line numbers). This surprised me - can anyone explain why this happens? e.g. #include <stdio.h> static void blah(void) { printf("hello world\n"); } int main(int argc, char *argv[]) { blah(); return 0; } gcc -o foo foo.c nm foo | grep blah: 08048374 t blah

    Read the article

  • Linker library for OpenMP for Snow Leopard?

    - by unknownthreat
    Currently, I am trying out OpenMP on XCode 3.2.2 on Snow Leopard: #include <omp.h> #include <iostream> #include <stdio.h> int main (int argc, char * const argv[]) { #pragma omp parallel printf("Hello from thread %d, nthreads %d\n", omp_get_thread_num(), omp_get_num_threads()); return 0; } I didn't include any linking libraries yet, so the linker complains: "_omp_get_thread_num", referenced from: _main in main.o "_omp_get_num_threads", referenced from: _main in main.o OK, fine, no problem, I take a look in the existing framework, looking for keywords such as openmp or omp... here comes the problem, where is the linking library? Or should I say, what is the name of the linking library for openMP? Is it dylib, framework or what? Or do I need to get it from somewhere first?

    Read the article

  • nul terminating a int array

    - by robUK
    Hello, gcc 4.4.4 c89 I was just experimenting with a int array. And something just came to my mind. Can I nul terminate it. For example, I am using a 0 to nul terminate. However, 0 could well be a valid value in this array. The code below will terminate after the 5. Even though I mean 0 to be a valid number. However, I could specify the size of the array. But in this case, I don't want to this as I am just interested in this particular problem. Many thanks for any advice, #include <stdio.h> static void test(int *p); int main(void) { int arr[] = {30, 450, 14, 5, 0, 10, '\0'}; test(arr); return 0; } static void test(int *p) { while(*p) { printf("Array values [ %d ]\n", *p++); } }

    Read the article

  • glibc backtrace - can't redirect output to file

    - by Jason Antman
    Hi, I'm in the process of debugging a C program (that I didn't write). I have all of the internal debugging tools (a whole bunch of printf's) enabled, and I wrote a small PHP script that uses proc_open() and just grabs both stdout and stderr, and time-coordinates them in one file. At the moment, the binary is dieing with a realloc() error that's caught by glibc, and a glibc backtrace is printed, beginning with: *** glibc detected *** /sbin/rsyslogd: realloc(): invalid next size: 0x00002ace626ac910 *** Here's the thing I don't understand: I've confirmed that the PHP script is catching both stdout and stderr from the binary's process and writing them to the correct files, but this backtrace is still printed to the console. Where is this coming from? Is there some magical output channel other than stdout and stderr? Any ideas on how I go about capturing this backtrace to a file, or sending it out with stderr? Thanks, Jason

    Read the article

  • How default assignment operator works in struct?

    - by skydoor
    Suppose I have a structure in C++ containing a name and a number, e.g. struct person { char name[20]; int ssn; }; Suppose I declare two person variables: person a; person b; where a.name = "George", a.ssn = 1, and b.name = "Fred" and b.ssn = 2. Suppose later in the code a = b; printf("%s %d\n",a.name, a.ssn);

    Read the article

  • Logic differences in C and Java

    - by paragjain16
    Compile and run this code in C #include <stdio.h> int main() { int a[] = {10, 20, 30, 40, 50}; int index = 2; int i; a[index++] = index = index + 2; for(i = 0; i <= 4; i++) printf("%d\n", a[i]); } Output : 10 20 4 40 50 Now for the same logic in Java class Check { public static void main(String[] ar) { int a[] = {10, 20, 30, 40, 50}; int index = 2; a[index++] = index = index + 2; for(int i = 0; i <= 4; i++) System.out.println(a[i]); } } Output : 10 20 5 40 50 Why is there output difference in both languages, output is understandable for Java but I cannot understand output in C One more thing, if we apply the prefix ++ operator, we get the same result in both languages, why?

    Read the article

  • Purpose of Trigraph sequences in C++?

    - by Kirill V. Lyadvinsky
    According to C++'03 Standard 2.3/1: Before any other processing takes place, each occurrence of one of the following sequences of three characters (“trigraph sequences”) is replaced by the single character indicated in Table 1. ---------------------------------------------------------------------------- | trigraph | replacement | trigraph | replacement | trigraph | replacement | ---------------------------------------------------------------------------- | ??= | # | ??( | [ | ??< | { | | ??/ | \ | ??) | ] | ??> | } | | ??’ | ˆ | ??! | | | ??- | ˜ | ---------------------------------------------------------------------------- In real life that means that code printf( "What??!\n" ); will result in printing What| because ??! is a trigraph sequence that is replaced with the | character. My question is what purpose of using trigraphs? Is there any practical advantage of using trigraphs? UPD: In answers was mentioned that some European keyboards don't have all the punctuation characters, so non-US programmers have to use trigraphs in everyday life? UPD2: Visual Studio 2010 has trigraph support turned off by default.

    Read the article

< Previous Page | 48 49 50 51 52 53 54 55 56 57 58 59  | Next Page >