converting int to char in C



Hi,



I am trying to convert a string length to a char and store it in an array. For some reason, even though its not giving me any error, when I try to print the array out, the place where I store the strlen is blank. Here's my code:



```
int main () {
char host[] = "www.google.com";
char delim[]=".";
int i=0, index=0;
char *token;
char buf[100];
unsigned char len_char;
int length;
 
token =  strtok(host, delim);
while (token != NULL) {
 length = strlen(token);
 len_char = (unsigned char) length;
 printf("%c", len_char);    //<this does not print anything too!!
 buf[index++] = length; //add the length as the beginning of a string
 //printf("here%c", buf[index++]);
 for(i=0; i<length; i++) {
  buf[index++] = token[i];
  //printf("%c", buf[index++]);
 }
 token = strtok(NULL, delim); 
}
printf("%d, %s\n", strlen(buf), buf);
return 0;
}
```

The output I get is as follows:



15, wwwgooglecom



where as I am expecting something like:  

15, 3www6google3com



Please note that the strlen(buf) gives the expected result. It's just that the numbers are not printed. Any help would be appreciated. Thanks.



-lilpro
>printf("%c", len\_char); //<this does not print anything too!!  

What did you expect it to print? You realize that the %c format modifier takes the integer value you supply and prints the character representation of that integer, right? In other words, it's not going to print '3'...ever. As long as the lengths are single digits, you can say len\_char + '0' and get the correct representation, but once the length exceeds 9, you're SOL with this method.
you write an int, but try to receive a c-string, that can not work.

the radio will not be available (i.e. have a packet received) 99.9% of the time,

introducing a delay and printing something if that is the case is just crazy.

so your code seems to be copy and pasted crap without any understandin… not [full disclosure] a linux person per se.

something similar to the following should work:

https://www.unix.com/shell-programming-and-scripting/68166-converting-integer-string.html

start simple with just enough code to test the concept.

see if it works and modify/correct as necessary.

then if it still does not work, then post your documented code accordingly along an explanation of what is or is not happening as you expect or desire. In C ++ 11, the code is well defined, but may not do what you expect. Exact Effects: 21.4.5 / 2:



>  Returns: `*(begin() + pos)`
>   
> 
> 
> 
> 
>  (adsbygoogle = window.adsbygoogle || []).push({});
>  
>   
> 
> if `pos < size()`
>   
> 
> 
> 
> 
>  (adsbygoogle = window.adsbygoogle || []).push({});
>  
>   
> 
> , otherwise a reference to an object of type `T`
>   
> 
> 
> 
> 
>  (adsbygoogle = window.adsbygoogle || []).push({});
>  
>   
> 
> with a value `charT()`
>   
> 
> 
> 
> 
>  (adsbygoogle = window.adsbygoogle || []).push({});
>  
>   
> 
> ; the reference value should not be changed.
> 
> 
> 



  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

So, if the string is not empty, it returns a reference to the beginning of the internal buffer. If empty, it returns a reference `char`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

with a value `0`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

whose location is implementation information. Unicode can be a problem, and Perl has its own quirks. Essentially, Perl creates a firewall that surrounds all Unicode I / O capabilities. You must tell Perl if the I / O path is encoded. If so, the DECODE rule for any input and / or ENCODE for any output.


Decoding converts the data from {encoding} to Perl's internal representation, which is probably a combination of bytes and code points.


The coding is just the opposite.


Thus, it is actually possible to "decode into" and "encode" up to two different encodings. You just need to say what it is. Encoding / decoding is usually done with the file I / O layer, but you can use the encoding module (distribution part) to manually convert between encodings.


 [perldocs in Unicode](https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=) does not read light.



  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

Here's an example that can help visualize it (there are many other ways).



```
use strict;
use warnings;
use Encode;


# This is an internalized string with these UTF-8 codepoints
# 
my $internal_string_1 = "\x{C7}\x{69}\x{64}\x{65}\x{6D}\x{5F}\x{15E}\x{65}\x{6E}\x{65}\x{72}\x{20}\x{48}\x{FC}\x{73}\x{6E}\x{FC}\x{20}\x{54}\x{61}\x{11F}\x{6C}\x{69}\x{70}";


# Open a temp file for writing as UTF-8.
# Output to this file will be automatically encoded from Perl internal to UTF-8 octets.
# Write the internal string.
# Check the file with a UTF-8 editor.
# 
open (my $out, '>:utf8', 'temp.txt') or die "can't open temp.txt for writing $!";
print $out $internal_string_1;
close $out;


# Open the temp file for readin as UTF-8.
# All input from this file will be automatically decoded as UTF-8 octets to Perl internal.
# Read/decode to a different internal string.
# 
open (my $in, '<:utf8', 'temp.txt') or die "can't open temp.txt for reading $!";
$/ = undef;
my $internal_string_2 = <$in>;
close $in;


# Change the binmode of STDOUT to UTF-8.
# Output to STDOUT will now be automatically encoded from Perl internal to UTF-8 octets.
# Capture STDOUT to a file then check with a UTF-8 editor.
# 
binmode STDOUT, ':utf8';
print $internal_string_2, "\n\n";


# Use encode() to convert an internal string to UTF-8 octets
# Format the UTF-8 octets to hex values
# Print to STDOUT
# 
my $octets = encode ("utf8", $internal_string_2);
print "Encoded (out) string -> UTF-8 (octets):\n";
print " length = ".length($octets)."\n";
print " octets = $octets\n";
print " HEX val = ";
for (split //, $octets) {
    printf ("0x%X ", ord($_));
}
print "\n\n";


# Use decode() to convert external UTF-8 octets to an internal string.
# Format the internal string to codepoints (hex values).
# Print to STDOUT.
# 
my $internal_string_3 = decode ("utf8", $octets);
print "Decoded (in) string <- UTF-8 (octets):\n";
print " length = ".length($internal_string_3)."\n";
print " string = $internal\_string\_3\n";
print " code points = ";
for (split //, $internal_string_3) {
    printf ("\\x{%X} ", ord($_));
}

        

        
        
        
 (adsbygoogle = window.adsbygoogle || []).push({});
 
        

    
```

Output



```
Çidem\_Şener Hüsnü Tağlip

Encoded (out) string -> UTF-8 (octets):
   length  =  29
   octets  =  Ãidem\_Åener HÃ¼snÃ¼ TaÄlip
   HEX val = 0xC3 0x87 0x69 0x64 0x65 0x6D 0x5F 0xC5 0x9E 0x65 0x6E 0x65 0x72 0x20 0x48 0xC3 0xBC 0x73 0x6E 0xC3 0xBC 0x20 0x54 0x61 0xC4 0x9F 0x6C 0x69 0x70

Decoded (in) string <- UTF-8 (octets):
   length      =  24
   string      =  Çidem\_Şener Hüsnü Tağlip
   code points = \x{C7} \x{69} \x{64} \x{65} \x{6D} \x{5F} \x{15E} \x{65} \x{6E} \x{65} \x{72} \x{20} \x{48} \x{FC} \x{73} \x{6E} \x{FC} \x{20} \x{54} \x{61} \x{11F} \x{6C} \x{69} \x{70}

        

        
        
        
 (adsbygoogle = window.adsbygoogle || []).push({});
 
        

    
``` How you do this will depend on a number of factors: since you haven't tried to explain in any detail, I'll assume you know nothing, and just give you the basics.  

  

The easiest way to do this is to read the text file into a single string, and then use the .NET framework to find the match:  


```
Dim text As String = File.ReadAllText("D:\Temp\MyFile.txt")
Dim index As Integer = text.IndexOf("hello")
If index >= 0 Then
   ' String is in file, starting at character "index"
End If
```
  

There are other ways, but that is pretty much the simplest. c = input()  

t = len(c)  

temp = ""  

for i in range(0,len(c)):  

    if t<3:  

        break  

    else:  

        if i in (0,1,t-2,t-1):  

            temp = temp+c[i]  

        else:  

            continue  

print(temp) hi,

sorry you are having issues with this. this is a known bug that was fixed in 2.24. the index of the loop is of an unsigned type in the generated c++ in 2.23. and since there are no negative numbers in unsigned types -1 becomes max integer.

issue where we found this: [https://github.com/stan-dev…](https://github.com/stan-dev/stanc3/issues/536) you are accidentally creating an array inside of an array: the .split() method returns an array, so you can simply set storywords equal to story.split(' '), instead of placing it inside of an array.

in its current form, storywords does only have length 1, because it only has one index: the resultan… The problem is that your pair's closure must return two different types of objects: int if you ask for "con", and the next closure on the line if you ask for "crd".


Here's one possible implementation:


Use a speaker so you can come back.



```
public static Func<string, dynamic> Pair(int x, Func<string, dynamic> y)
{
    Func<string, dynamic> pair =
           (a) =>
           {
               if (a == "con") return x;
               if (a == "crd") return y;
               throw new Exception();
           };

    return pair;
}

public static void Print(Func<string, dynamic> pair)
{
    while (true)
    {
        var next = pair("crd");
        Console.WriteLine((next == null ? "-":"+") +"> " + pair("con"));
        if (next != null)
        {
            Console.WriteLine("|");
            pair = (x) => next(x);
            continue;
        }
        break;
    }
}

        

        
        
        
 (adsbygoogle = window.adsbygoogle || []).push({});
 
        

    
```


  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

Test:



```
var pair = Pair(1,
            Pair(2,
                  Pair(3,
                        Pair(4, null))));

Print(pair);

        

        
        
        
 (adsbygoogle = window.adsbygoogle || []).push({});
 
        

    
```

output:



```
+> 1
|
+> 2
|
+> 3
|
-> 4

        

        
        
        
 (adsbygoogle = window.adsbygoogle || []).push({});
 
        

    
``` `for i in count:` means `for i in 7:`, which won't work. The bit after the `in` should be of an iterable type, not a number. Try this:



```
for i in range(count):

```