<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic C or script help in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/c-or-script-help/m-p/4910345#M702804</link>
    <description>Hi -- &lt;BR /&gt;&lt;BR /&gt;I haven't written a lot of C and I'm looking for help on a particular task.&lt;BR /&gt;&lt;BR /&gt;I want to read in a file and print out a numerical representation of it.  In particular, I'd like to have every non-space character represented by a number and then have each word represented by the sum of it's letters.&lt;BR /&gt;&lt;BR /&gt;I'm not concerned what the numbers are that represent the letters (i.e. if there is a routine out there that will do this using some standard, then that's fine).&lt;BR /&gt;&lt;BR /&gt;For instance, if a script used a numbering format of a=1 to z=26 then I'd want the input line of.&lt;BR /&gt;&lt;BR /&gt;hello world&lt;BR /&gt;&lt;BR /&gt;to output as&lt;BR /&gt;&lt;BR /&gt;52 72&lt;BR /&gt;&lt;BR /&gt;I can figure out how to read in lines into a C program okay, the part I don't know how to do is the conversion from a character to a numerical represenation.  &lt;BR /&gt;&lt;BR /&gt;If anyone can post a C code or script that will do what I'm looking for, it would be greatly appreciated and you will get points (I've got a 100% record on that).&lt;BR /&gt;&lt;BR /&gt;Best regards,&lt;BR /&gt;&lt;BR /&gt;Oz&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Mon, 04 Jul 2005 00:24:14 GMT</pubDate>
    <dc:creator>Kent Ostby</dc:creator>
    <dc:date>2005-07-04T00:24:14Z</dc:date>
    <item>
      <title>C or script help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/c-or-script-help/m-p/4910345#M702804</link>
      <description>Hi -- &lt;BR /&gt;&lt;BR /&gt;I haven't written a lot of C and I'm looking for help on a particular task.&lt;BR /&gt;&lt;BR /&gt;I want to read in a file and print out a numerical representation of it.  In particular, I'd like to have every non-space character represented by a number and then have each word represented by the sum of it's letters.&lt;BR /&gt;&lt;BR /&gt;I'm not concerned what the numbers are that represent the letters (i.e. if there is a routine out there that will do this using some standard, then that's fine).&lt;BR /&gt;&lt;BR /&gt;For instance, if a script used a numbering format of a=1 to z=26 then I'd want the input line of.&lt;BR /&gt;&lt;BR /&gt;hello world&lt;BR /&gt;&lt;BR /&gt;to output as&lt;BR /&gt;&lt;BR /&gt;52 72&lt;BR /&gt;&lt;BR /&gt;I can figure out how to read in lines into a C program okay, the part I don't know how to do is the conversion from a character to a numerical represenation.  &lt;BR /&gt;&lt;BR /&gt;If anyone can post a C code or script that will do what I'm looking for, it would be greatly appreciated and you will get points (I've got a 100% record on that).&lt;BR /&gt;&lt;BR /&gt;Best regards,&lt;BR /&gt;&lt;BR /&gt;Oz&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 04 Jul 2005 00:24:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/c-or-script-help/m-p/4910345#M702804</guid>
      <dc:creator>Kent Ostby</dc:creator>
      <dc:date>2005-07-04T00:24:14Z</dc:date>
    </item>
    <item>
      <title>Re: C or script help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/c-or-script-help/m-p/4910346#M702805</link>
      <description>how to do is the conversion from a character to a numerical represenation:&lt;BR /&gt;&lt;BR /&gt;doesn't sprintf do that.&lt;BR /&gt;or how about the atoi function call&lt;BR /&gt;&lt;BR /&gt;here is a somewhat trival script, i.e every character is mapped to one, or just prints out the number of characters in each word.&lt;BR /&gt;&lt;BR /&gt;cat file |&lt;BR /&gt;awk '{&lt;BR /&gt;for ( i=1;i&amp;lt;=NF;i++) {&lt;BR /&gt;l=length($i);&lt;BR /&gt;if ( i = 1 ) printf("%d",l);&lt;BR /&gt;else printf(" %d",l);&lt;BR /&gt;}&lt;BR /&gt;printf("\n",);&lt;BR /&gt;}'&lt;BR /&gt;&lt;BR /&gt;you might have to work with that to handle empty lines and multiple spaces, i.e more then one blank in a row.</description>
      <pubDate>Mon, 04 Jul 2005 01:24:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/c-or-script-help/m-p/4910346#M702805</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2005-07-04T01:24:34Z</dc:date>
    </item>
    <item>
      <title>Re: C or script help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/c-or-script-help/m-p/4910347#M702806</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;You can try to work with &lt;BR /&gt;od -b:&lt;BR /&gt;&lt;BR /&gt; echo hello |od -b&lt;BR /&gt;0000000 150 145 154 154 157 012&lt;BR /&gt;0000006&lt;BR /&gt;&lt;BR /&gt;This command gives you octal for each character in the input&lt;BR /&gt;&lt;BR /&gt;HTH</description>
      <pubDate>Mon, 04 Jul 2005 03:14:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/c-or-script-help/m-p/4910347#M702806</guid>
      <dc:creator>Victor Fridyev</dc:creator>
      <dc:date>2005-07-04T03:14:56Z</dc:date>
    </item>
    <item>
      <title>Re: C or script help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/c-or-script-help/m-p/4910348#M702807</link>
      <description>Hi Kent, in awk you can make a script like this:&lt;BR /&gt;-------------------- s.awk ---------------&lt;BR /&gt;BEGIN {&lt;BR /&gt;  v["a"]=1; v["b"]=2; v["c"]=3; v["d"]=4; v["e"]=5&lt;BR /&gt;  v["f"]=6; v["g"]=7; v["h"]=8; v["i"]=9; v["j"]=10&lt;BR /&gt;  v["k"]=11; v["l"]=12; v["m"]=13; v["n"]=14; v["o"]=15&lt;BR /&gt;  v["p"]=16; v["q"]=17; v["r"]=18; v["s"]=19; v["t"]=20&lt;BR /&gt;  v["u"]=21; v["v"]=22; v["w"]=23; v["x"]=24; v["y"]=25&lt;BR /&gt;  v["z"]=26; &lt;BR /&gt;  v["0"]=27; v["1"]=28; v["2"]=29; v["3"]=30; v["4"]=31&lt;BR /&gt;  v["5"]=32; v["6"]=33; v["7"]=34; v["8"]=35; v["9"]=36&lt;BR /&gt;  w=0&lt;BR /&gt;} &lt;BR /&gt;&lt;BR /&gt;{ &lt;BR /&gt;  for (i=1;i&amp;lt;=NF;i++) {&lt;BR /&gt;    for (j=1;j&amp;lt;=length($i);j++) {&lt;BR /&gt;      c=substr($i,j,1)&lt;BR /&gt;      w+=v[c]&lt;BR /&gt;    }&lt;BR /&gt;    printf("%d ",w) ; w=0&lt;BR /&gt;  }&lt;BR /&gt;  printf("\n")&lt;BR /&gt;}&lt;BR /&gt;---------- end s.awk -----------&lt;BR /&gt;&lt;BR /&gt;You can do now, awk -f s.awk file&lt;BR /&gt;&lt;BR /&gt;nevertheless, in C code the ascii value of a character is 'c' for example printf("%d",'0') gives you the number 48&lt;BR /&gt;&lt;BR /&gt;Frank.</description>
      <pubDate>Mon, 04 Jul 2005 03:16:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/c-or-script-help/m-p/4910348#M702807</guid>
      <dc:creator>Francisco J. Soler</dc:creator>
      <dc:date>2005-07-04T03:16:20Z</dc:date>
    </item>
    <item>
      <title>Re: C or script help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/c-or-script-help/m-p/4910349#M702808</link>
      <description>to use the ascii values with francisco's awk script I used this for the begin&lt;BR /&gt;&lt;BR /&gt;BEGIN {&lt;BR /&gt;for (i=0;i&amp;lt;256;i++){&lt;BR /&gt;a=sprintf("%c",i);&lt;BR /&gt;v[a]=i;&lt;BR /&gt;&lt;BR /&gt;and if you'd like to do the same thing as a script:&lt;BR /&gt;&lt;BR /&gt;cat d1|&lt;BR /&gt;while read line&lt;BR /&gt;do&lt;BR /&gt;set -A var $line&lt;BR /&gt;numWords=${#var[*]}&lt;BR /&gt;x=0&lt;BR /&gt;while (( x &amp;lt; $numWords ))&lt;BR /&gt;do&lt;BR /&gt;word="${var[$x]}"&lt;BR /&gt;lengthWord=${#word}&lt;BR /&gt;count=0&lt;BR /&gt;typeset -L1 char&lt;BR /&gt;y=0&lt;BR /&gt;while (( $y &amp;lt; lengthWord ))&lt;BR /&gt;do&lt;BR /&gt;if (( $y == 0 )) ;then&lt;BR /&gt;  char=$word&lt;BR /&gt;else&lt;BR /&gt;  eval typeset -L$y start&lt;BR /&gt;  start=$word&lt;BR /&gt;  last=${word#$start}&lt;BR /&gt;  char=$last&lt;BR /&gt;fi&lt;BR /&gt;printf "%d\n" $char | read value&lt;BR /&gt;((count=$count+value))&lt;BR /&gt;(( y = $y +1))&lt;BR /&gt;done&lt;BR /&gt;if (( $x == 0 )) ;then&lt;BR /&gt;print "$count\c"&lt;BR /&gt;else&lt;BR /&gt;print -- " $count\c"&lt;BR /&gt;fi&lt;BR /&gt;(( x = $x +1))&lt;BR /&gt;done&lt;BR /&gt;print&lt;BR /&gt;done&lt;BR /&gt;</description>
      <pubDate>Mon, 04 Jul 2005 05:03:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/c-or-script-help/m-p/4910349#M702808</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2005-07-04T05:03:29Z</dc:date>
    </item>
    <item>
      <title>Re: C or script help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/c-or-script-help/m-p/4910350#M702809</link>
      <description>and for a little C code&lt;BR /&gt;&lt;BR /&gt;include &lt;STDIO.H&gt;&lt;BR /&gt;include &lt;CTYPE.H&gt;&lt;BR /&gt;&lt;BR /&gt;void main(void)&lt;BR /&gt;{&lt;BR /&gt;FILE *fp;&lt;BR /&gt;int charValue;&lt;BR /&gt;int count;&lt;BR /&gt;&lt;BR /&gt;/*open  your file, something like this&lt;BR /&gt;*/&lt;BR /&gt;if ( (fp = fopen ("test", "r")) == NULL ) {&lt;BR /&gt;  printf("test couldn't be opened\n");&lt;BR /&gt;  exit(1);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;while (!feof(fp)) {&lt;BR /&gt;  count=0&lt;BR /&gt;  while (!isspace(charValue=getc(fp) )&lt;BR /&gt;     count=count+charValue;&lt;BR /&gt;     ungetc(charValue,fp);&lt;BR /&gt;  while (isspace(charValue=getc(fp) )&lt;BR /&gt;     /* you'll need to print out your value&lt;BR /&gt;      * here with appropriate formating&lt;BR /&gt;     */&lt;BR /&gt;     printf("%d",count);&lt;BR /&gt;     count=0;&lt;BR /&gt;     /* you'll need to test for newline&lt;BR /&gt;      * so you can terminate your line&lt;BR /&gt;     */&lt;BR /&gt;     ungetc(charValue,fp);&lt;BR /&gt;  }&lt;BR /&gt;}&lt;BR /&gt;&lt;/CTYPE.H&gt;&lt;/STDIO.H&gt;</description>
      <pubDate>Mon, 04 Jul 2005 05:40:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/c-or-script-help/m-p/4910350#M702809</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2005-07-04T05:40:57Z</dc:date>
    </item>
    <item>
      <title>Re: C or script help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/c-or-script-help/m-p/4910351#M702810</link>
      <description>Here is a C code for the same.&lt;BR /&gt;&lt;BR /&gt;==================&lt;BR /&gt;#include&lt;STDIO.H&gt;&lt;BR /&gt;#include&lt;LIMITS.H&gt;&lt;BR /&gt;&lt;BR /&gt;int main() {&lt;BR /&gt;&lt;BR /&gt;  FILE *fp;&lt;BR /&gt;  char buf[LINE_MAX+1];&lt;BR /&gt;&lt;BR /&gt;  fp = fopen("filename.dat", "r");&lt;BR /&gt;  buf[LINE_MAX]='\0';&lt;BR /&gt;    fscanf(fp, "%s", buf);&lt;BR /&gt;  while(!feof(fp)) {&lt;BR /&gt;    int i=0, sum=0;&lt;BR /&gt;    for(i=0; i&lt;LINE_MAX&gt;&lt;/LINE_MAX&gt;      if((buf[i] &amp;gt;= 'A') &amp;amp;&amp;amp; (buf[i] &amp;lt;= 'Z')) {&lt;BR /&gt;        sum += (buf[i] - 'A' + 1);&lt;BR /&gt;        continue;&lt;BR /&gt;      }&lt;BR /&gt;      if((buf[i] &amp;gt;= 'a') &amp;amp;&amp;amp; (buf[i] &amp;lt;= 'z')) {&lt;BR /&gt;        sum += (buf[i] - 'a' + 1);&lt;BR /&gt;        continue;&lt;BR /&gt;                        }&lt;BR /&gt;    }&lt;BR /&gt;    printf("%d ", sum);&lt;BR /&gt;    fscanf(fp, "%s", buf);&lt;BR /&gt;  }&lt;BR /&gt;  printf("\n");&lt;BR /&gt;  fclose(fp);&lt;BR /&gt;}&lt;BR /&gt;==================&lt;BR /&gt;I hope this helps.&lt;BR /&gt;-Amit&lt;/LIMITS.H&gt;&lt;/STDIO.H&gt;</description>
      <pubDate>Mon, 04 Jul 2005 05:43:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/c-or-script-help/m-p/4910351#M702810</guid>
      <dc:creator>Amit Agarwal_1</dc:creator>
      <dc:date>2005-07-04T05:43:41Z</dc:date>
    </item>
    <item>
      <title>Re: C or script help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/c-or-script-help/m-p/4910352#M702811</link>
      <description>Thanks for all the ideas so far.&lt;BR /&gt;&lt;BR /&gt;I will try them out in the next few days and post points as I go.&lt;BR /&gt;&lt;BR /&gt;For anyone else posting, please note that I really want to print out the word totals versus the letter totals although I do appreciate the various suggestions.&lt;BR /&gt;</description>
      <pubDate>Mon, 04 Jul 2005 07:50:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/c-or-script-help/m-p/4910352#M702811</guid>
      <dc:creator>Kent Ostby</dc:creator>
      <dc:date>2005-07-04T07:50:29Z</dc:date>
    </item>
    <item>
      <title>Re: C or script help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/c-or-script-help/m-p/4910353#M702812</link>
      <description>There's something very simple you need to remember.&lt;BR /&gt;&lt;BR /&gt;Each and every letter is made up of an ASCII character which is the same on all computers, so you don't need to worry about setting up array's of character values, as they all already have one, jsut with a given off-set.&lt;BR /&gt;&lt;BR /&gt;For instance, the character 'A' = 65.  The character 'a' = 97.&lt;BR /&gt;&lt;BR /&gt;Simply put, if the 7th bit is on (but not 8th), it's a letter.  The 6th bit determines the case (on = lower, off = upper).  The first 5 bits determine it's value (1-31).  The 5 characters slack are brackes, brackets and other special characters (i.e. 64 = @, 96 - `).&lt;BR /&gt;&lt;BR /&gt;Armed with this, you should very simply be able to loop through the characters, breaking at chr32, adding the individual digits, taking into account the bit-offset's.&lt;BR /&gt;&lt;BR /&gt;        int a = 'a';&lt;BR /&gt;        printf( "%d\n", a );&lt;BR /&gt;&lt;BR /&gt;Remember, code like this is prefectly ok.</description>
      <pubDate>Mon, 04 Jul 2005 18:41:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/c-or-script-help/m-p/4910353#M702812</guid>
      <dc:creator>Stuart Browne</dc:creator>
      <dc:date>2005-07-04T18:41:41Z</dc:date>
    </item>
    <item>
      <title>Re: C or script help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/c-or-script-help/m-p/4910354#M702813</link>
      <description>You can easily do with c programming as,&lt;BR /&gt;&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;&lt;BR /&gt;main() {&lt;BR /&gt;&lt;BR /&gt;  FILE *fp;&lt;BR /&gt;  char c;&lt;BR /&gt;  int i=0;&lt;BR /&gt;  &lt;BR /&gt;  /* File test.log has to be there */&lt;BR /&gt;&lt;BR /&gt;  fp=fopen("test.log","r");&lt;BR /&gt;  &lt;BR /&gt;  if ( !fp ) {&lt;BR /&gt;   &lt;BR /&gt;     printf ("No file is available as test.log\n");&lt;BR /&gt;     exit (1);&lt;BR /&gt;     &lt;BR /&gt;   } &lt;BR /&gt;   &lt;BR /&gt;  &lt;BR /&gt;  /* If loops for string format and sum */&lt;BR /&gt;&lt;BR /&gt;  while ((c=getc(fp))!=EOF){&lt;BR /&gt;&lt;BR /&gt;    if ( c != '\n' &amp;amp;&amp;amp; c != ' ' ) {&lt;BR /&gt;      printf ("%c",c);&lt;BR /&gt;    }&lt;BR /&gt;&lt;BR /&gt;    i=i+c;&lt;BR /&gt;&lt;BR /&gt;    if ( c == ' ' || c == '\n' ) {&lt;BR /&gt;      printf ("=%d ",i);&lt;BR /&gt;    }&lt;BR /&gt;&lt;BR /&gt;    if ( c == '\n')  {&lt;BR /&gt;      printf ("%c",c);&lt;BR /&gt;    }&lt;BR /&gt;    if ( c == ' ') {&lt;BR /&gt;      printf ("'%c'=1 ",c);&lt;BR /&gt;    }&lt;BR /&gt;&lt;BR /&gt;  }&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;hth.&lt;/STDIO.H&gt;</description>
      <pubDate>Tue, 05 Jul 2005 04:45:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/c-or-script-help/m-p/4910354#M702813</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2005-07-05T04:45:37Z</dc:date>
    </item>
    <item>
      <title>Re: C or script help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/c-or-script-help/m-p/4910355#M702814</link>
      <description>Thanks guys.  This is great stuff.&lt;BR /&gt;&lt;BR /&gt;Just what I needed.  I may be back another time with some other questions since I have a complex project in mind, but haven't done much C coding (done a bit of 'C' reading).&lt;BR /&gt;</description>
      <pubDate>Tue, 05 Jul 2005 07:30:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/c-or-script-help/m-p/4910355#M702814</guid>
      <dc:creator>Kent Ostby</dc:creator>
      <dc:date>2005-07-05T07:30:16Z</dc:date>
    </item>
    <item>
      <title>Re: C or script help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/c-or-script-help/m-p/4910356#M702815</link>
      <description>All the 10 pt rated solutions above worked right out of the box which is what I was looking for.&lt;BR /&gt;&lt;BR /&gt;I appreciate the other hints and tips also given.&lt;BR /&gt;</description>
      <pubDate>Tue, 05 Jul 2005 07:31:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/c-or-script-help/m-p/4910356#M702815</guid>
      <dc:creator>Kent Ostby</dc:creator>
      <dc:date>2005-07-05T07:31:08Z</dc:date>
    </item>
  </channel>
</rss>

