How to find length of string and pass into char array in C?


 
Thread Tools Search this Thread
Top Forums Programming How to find length of string and pass into char array in C?
# 1  
Old 05-28-2011
How to find length of string and pass into char array in C?

Hi All
I want to take a Hexadecimal number as input and i want to find lenth of the input and pass it to char s[] ( char s[length of the input] ). I have a program to convert hexadecial to binary but it is taking limited input but i want to return binary number based on input. How?
# 2  
Old 05-28-2011
What i have read in one of my book is :

A constant integer written in headecimal form will take the first of the following type whose size is sufficient to represent it correctly : int, unsigned int, long int, unsigned long int.
you can still force the compiler to use a type long or unsigned by adding the L|l or U|u :

0xFFl
0xFFFFu
0xFFFFlu

In the case your constant is positive and exceed the capacity of the type unsigned long int
OR
In the case your constat is negative and is lower than the lowest number that can be represented in with the type int
... then the ANSI norm does not specify the behaviour (so it may depend on the implementation of your compiler, some will truncate bits to only keep those with 'heavy weight' ... some may return strange result...)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Views How to replace a CRLF char from a variable length file in the middle of a string in UNIX?

My sample file is variable length, with out any field delimiters. It has min of 18 chars length and the 'CRLF' is potentially between 12-14 chars. How do I replace this with a space? I still want to keep end of record, but just want to remove these new lines chars in the middle of the data. ... (7 Replies)
Discussion started by: chandrath
7 Replies

2. Shell Programming and Scripting

How to find length of multidimension array ???

Does anyone know how to find length of multi dimension array of following type A Afor simple array I is to do for (i in A)n++ to find length of array but if it is multi dimension how to find the length ? (2 Replies)
Discussion started by: nex_asp
2 Replies

3. Programming

Fastest way to find the length of string in c

Hi all, We use strlen() fun provided by library to find the length of a string. Looking inside of it, it has some different mechanism to find the length of string. Normally, we scan the string byte by byte until the '\0' character. It takes a logn time to count length. The Library strlen()... (2 Replies)
Discussion started by: yogeshrl9072
2 Replies

4. Shell Programming and Scripting

Longest length of string in array

I would be grateful if someone could help me. I am trying to write a .sh script in UNIX. I have the following code; User=john User=james User=ian User=martin for x in ${User} do print ${#x} done This produces the following output; 4 5 3 6 (12 Replies)
Discussion started by: mmab
12 Replies

5. Shell Programming and Scripting

Replacing one Char in a string of variable length

Hi all, I am trying to find the best way of making a change to 1 char in a string, the string can be between 1 and 14 characters. I am reading a line in from a file which contains 012341231231:2:102939283:NNN: Require :NBN: 012838238232:3:372932:NNN: Require :NNB: I need to change 1 N or a... (8 Replies)
Discussion started by: nkwilliams
8 Replies

6. Programming

pass char string via system()

hello all i am trying to pass a argument through system function to a shell script. #shell script echo.sh to display the string echo $1 and the c program is. #include<stdlib.h> int main() { const char *str = "hello all"; system("sh echo.sh str"); } the output i... (5 Replies)
Discussion started by: zius_oram
5 Replies

7. UNIX for Dummies Questions & Answers

Read a string with leading spaces and find the length of the string

HI In my script, i am reading the input from the user and want to find the length of the string. The input may contain leading spaces. Right now, when leading spaces are there, they are not counted. Kindly help me My script is like below. I am using the ksh. #!/usr/bin/ksh echo... (2 Replies)
Discussion started by: dayamatrix
2 Replies

8. Shell Programming and Scripting

find the string length in solaris

how to find the string length in solaris machine. (4 Replies)
Discussion started by: din_annauniv
4 Replies

9. Programming

md5 hash a string or char array in SCO

Can someone provide me with code to md5 hash a string or character array in the SCO environment. All help is appreciated thanks. (5 Replies)
Discussion started by: jcarter2333
5 Replies

10. UNIX for Dummies Questions & Answers

string of 7 char length always...

Hi, I know, particular value in the variable should always be of lenth 7 , but the value that is present in thevariable might be of any no.of characters less than or equal to 7... if the no.of characters in the variable is less than 7, I want to add, zeroes at the starting of the field.. How can... (3 Replies)
Discussion started by: thanuman
3 Replies
Login or Register to Ask a Question