One thing new and I never found in any book I've read is Using char as subscript for char array m[256], m['A']; m['T']...;
What is a character but a smaller integer? Single-character constants count as integers.
Quote:
Two more questions:
1) Any specific reason to have m[256] instead of m[4], which should be enough for this case?
4 is not enough: printf("%d %d %d %d\n", 'A', 'T', 'C', 'G'); prints 65 84 67 71 You will note these correspond exactly to the ASCII character table.
The array is a look-up table, like a Caesar cipher, big enough to cover the entire ASCII range. This is very simple to do and lets you translate with a single instruction.
It's also one reason it should be a global variable. Global variables are guaranteed to have any contents you don't initialize, set to binary 0. Not that we're using any other contents, but if garbage gets in, it's reassuring to know garbage won't come back out.
Quote:
2) in revcomp() function, what's the reason using output = input;. I would normally allocate new memory for output. (---That's the difference between pro and novice!)
Thanks!
The same reason I used strdup -- to make a new string of correct length. I don't really care what's in it as long as it's long enough. I think this is more efficient than calling string.push_back() 570 times.
But strings have a lot of properties of vectors, so I could also have done this:
...which is probably better, especially if input happens to be large. No point copying it then just overwriting it.
Last edited by Corona688; 10-29-2014 at 12:48 PM..
When run it, segment fault.
What is wrong?
#include <stdio.h>
#include <stdlib.h>
const int max =20;
//****************************************************
// Input Matrix
//****************************************************
void inMatrixAA(int *AA, int row, int col)... (9 Replies)
Dear all,
I used debugger from C++ and these are the message I got:
Program received signal SIGSEGV, Segmentation fault.
0x00323fc0 in free () from /lib/tls/libc.so.6
(gdb) info s
#0 0x00323fc0 in free () from /lib/tls/libc.so.6
#1 0x00794fa1 in operator delete () from... (5 Replies)
Hi
some help read............
I'm getting a segmentation fault when I run an AIX COBOL/Db2 program.
I initiate the program from the command line, but it hangs, and then when I press enter it generates a segmantation fault and produces a core dump.
The box is running AIX software level ... (5 Replies)
Hi all
In the ltp-posix test,there is a case in open_posix_testsuite\conformance\interfaces\timer_gettime\speculative/6-1.c
I run the above code,it will has a segment fault, if I modify it to below,it works well
Anybody can tell me why? (1 Reply)
I´m writing this program in QNX , I`m kinda new to UNIX and programing in general, and when I try to run it it gives me the Memory Fault error. Can anyone help?
#include <stdio.h>
#include <fcntl.h>
void main(void)
{int a,ter;
char buf;
printf("a=");
scanf("%d",a);
ter=open... (6 Replies)
Hi,
Whether the following piece of code is placed in the read-only memory of code (text) segment or data segment?
char *a = "Hello";
I am getting two different answers while searching in google :( that's why the confusion is (7 Replies)
I always get segment fault, why? can sb help me and modify it, I have spend on much time on
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <string.h>
#define MAX 10
pthread_t thread;
void *thread1()
{
int *a;
int i, n;
... (1 Reply)
Hello everybody,
I've been working on a program on my Linux box, after finished the code, i compile it with gcc -Wall option, so i can see what's wrong or unused.
The Walll output shows nothing, so there are no loose ends on the program.
I run the program on my system, and it works PERFECTLY.... (5 Replies)
Hi
I have struggling a week to fix a program , in the begining i got SIGBUS , but after many attempts still the program gets SIGSEGV segment fault , In bellow i post the seg fault log + source codes. would really appreciate if experts help me to fix this segment fault error. any advice is... (2 Replies)
Hello,
This function was copied into my code, which was compiled without error/warning, but when executed there is always Segmentation fault at the end after the output (which seems correct!):
void get_hashes(unsigned int hash, unsigned char *in)
{
unsigned char *str = in;
int pos =... (7 Replies)