why ? reversing postion results in different result

This is a discussion on why ? reversing postion results in different result within the C Programming forums, part of the General Programming Boards category; source code1: Code: char qseq[] = {'G'}; char sseq[] = {'A','C','G','T','G','T','A','T'}; printf("%s\n",qseq); result :G?" source code2: Code: char sseq[] = ...

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    168

    why ? reversing postion results in different result

    source code1:
    Code:
         char qseq[] = {'G'};
         char sseq[] = {'A','C','G','T','G','T','A','T'};
         printf("%s\n",qseq);
    result:G?"
    source code2:
    Code:
         char sseq[] = {'A','C','G','T','G','T','A','T'};
         char qseq[] = {'G'};
         printf("%s\n",qseq);
    result:
    GACGTGTAT?"

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    >> why ? reversing postion results in different result

    printf traverses the string until it encounters a null terminator. In this case, you haven't supplied any, so it just keeps going until it happens to encounter one on the stack (or crashes). You could have used:

    Code:
    char qseq[] = {'G', 0};
    // or perhaps
    char qseq[] = "G";
    Note that in the second example the null terminator is implied.

  3. #3
    Registered User
    Join Date
    Aug 2009
    Posts
    168
    Quote Originally Posted by Sebastiani View Post
    >> why ? reversing postion results in different result

    printf traverses the string until it encounters a null terminator. In this case, you haven't supplied any, so it just keeps going until it happens to encounter one on the stack (or crashes). You could have used:

    Code:
    char qseq[] = {'G', 0};
    // or perhaps
    char qseq[] = "G";
    Note that in the second example the null terminator is implied.
    Thanks.

    On the 64bit server the array maxium length? Is the length of the stack?

    maxium length?

  4. #4
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,274
    Quote Originally Posted by zcrself View Post
    Thanks.

    On the 64bit server the array maxium length? Is the length of the stack?

    maxium length?
    There is no definite maximum size for an automatic (stack) variable, but it does depend on the stack size. Since the stack is used for both local variables and to keep track of function calls, it's not a good idea to use up all your stack space for variable storage by declaring very large automatic variables. If you are using a data structure (array, struct) of significant size, allocate it dynamically with malloc().
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  5. #5
    Registered User
    Join Date
    Aug 2009
    Posts
    168
    Quote Originally Posted by brewbuck View Post
    There is no definite maximum size for an automatic (stack) variable, but it does depend on the stack size. Since the stack is used for both local variables and to keep track of function calls, it's not a good idea to use up all your stack space for variable storage by declaring very large automatic variables. If you are using a data structure (array, struct) of significant size, allocate it dynamically with malloc().
    Thanks your reply!

    My server has 64G memory,and now I have a 50G file,now I want 50G putting into memory!
    which data struct is best?
    How to read into memory?

  6. #6
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,274
    Quote Originally Posted by zcrself View Post
    Thanks your reply!

    My server has 64G memory,and now I have a 50G file,now I want 50G putting into memory!
    which data struct is best?
    How to read into memory?
    Loading a file that size into memory is almost certainly not the right thing to do. Unless you are going to be doing processing that demands that all the file data be immediately available, it seems like an almost crazy waste of resources.

    Even if you could read 100 MB/s, it would take about 8.5 minutes to load 50 GB into memory.

    EDIT: Upon glancing at your code again, are you doing some kind of bioinformatics processing? Then it MIGHT be justifiable to have the whole thing in RAM, but even then maybe not. I don't know a whole lot about bioinformatics algorithms.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  7. #7
    Registered User
    Join Date
    Aug 2009
    Posts
    168
    Quote Originally Posted by brewbuck View Post
    Loading a file that size into memory is almost certainly not the right thing to do. Unless you are going to be doing processing that demands that all the file data be immediately available, it seems like an almost crazy waste of resources.

    Even if you could read 100 MB/s, it would take about 8.5 minutes to load 50 GB into memory.

    EDIT: Upon glancing at your code again, are you doing some kind of bioinformatics processing? Then it MIGHT be justifiable to have the whole thing in RAM, but even then maybe not. I don't know a whole lot about bioinformatics algorithms.
    Yes I am doing bioinformatics processing!
    Now there are two files:
    file1:
    cigar::50 HWI-EAS-249_35:6:1:6:1154#0/2 76 32 - chromosome06 8365857 8365901 +
    ....
    ....
    ....

    file2:
    @HWI-EAS-249_35:6:1:6:1154#0/2
    GGGGGGCTGAGAAGGTTGAGACAAGTAAGGTATTTCTACGTGATACTAGT GTTATTTCTCCTTACTCGCTCCTTCT
    +
    BBBBBC@CC@B?@C@;A>:<58@><4;>>@*8@AB;B;6>7>3=66?315 <8@8@@?/>47?;88@%%%%%%%%%%
    ....
    ....
    ....
    ....

    these two files have more than 3,000,000 lines ,I want to produce the structure(as follows)

    HWI-EAS-249_35:6:1:6:1154#0/2 76 32 - chromosome06 8365857 8365901 + GGGGGGCTGAGAAGGTTGAGACAAGTAAGGTATTTCTACGTGATACTAGT GTTATTTCTCCTTACTCGCTCCTTCT
    .....
    ......
    .....

    according to keyword search the sequences,

    As I think , I want to create hash table to store the data so that giving me a keyword I can find its sequences quickly!

    Have best method to complete this job?

    the keyword is the second column every line of the file1
    Last edited by zcrself; 08-12-2009 at 01:15 AM.

  8. #8
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Quote Originally Posted by brewbuck View Post
    Upon glancing at your code again, are you doing some kind of bioinformatics processing? Then it MIGHT be justifiable to have the whole thing in RAM, but even then maybe not. I don't know a whole lot about bioinformatics algorithms.
    If they're DNA sequences it might even be useful to store them in a more compressed structure - since there are only four possible values, you really only need two bits to encode each sequence. Percentage-wise, that may not sound like a lot of savings, but when you're talking about a 50GB file that works out to like 37.5GB less storage!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with basic calculation program.
    By StateofMind in forum C Programming
    Replies: 18
    Last Post: 03-06-2009, 01:44 AM
  2. Promblem with code
    By watchdogger in forum C Programming
    Replies: 18
    Last Post: 01-31-2009, 06:36 PM
  3. Can someone help with my seg fault?
    By John_L in forum C++ Programming
    Replies: 23
    Last Post: 03-01-2008, 04:04 PM
  4. Need help with 'C' Program (arrays)
    By thephreak6 in forum C Programming
    Replies: 1
    Last Post: 10-24-2002, 01:36 AM
  5. Unreal results from FloatToStr function!!!!!!
    By ma55acre in forum Windows Programming
    Replies: 3
    Last Post: 04-04-2002, 02:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21