Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Donate Today!

Do you enjoy these
technical forums?
Donate Today! Click Here

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

PROFESSORSPARKIE (Instructor)
25 Apr 06 15:48
I have tried every combination of use for the 'upcase' function and keep getting mismatch data types and i am only using char & strings.

I want to read a file and loop through the input string record changing all characters to upper case and then print the records.

I have written many programs in many languages but this has me stumped.

I tried it in turbo and q-pascal. I prefer q-pascal for standalone filter programs.

any help? I just need the record loop statements 6 or 7.

thanks in advance.
stackdump (TechnicalUser)
25 Apr 06 16:35

I Actually use FP but if you create a small program like;

CODE

VAR
InChar : CHAR;

BEGIN
    WRITE(Enter a character: ');
    READLN(InChar);
    WRITELN(Upcase(InChar));
END.

Does this work?

what about...

CODE

VAR
A : RECORD
        n : INTEGER;
        m : CHAR;
    END;

BEGIN
    READLN(A.m);
    WRITELN(UPCASE(A.m));
END.
PROFESSORSPARKIE (Instructor)
25 Apr 06 22:42
Your answer looks simple enough but I am trying to read a line record into a string and make sure each character in the string is upper case and then print out the record string. My problem is the non support of upcase on a string and getting each character out of the string convert and build the string back.

This simple filter logic works for many utilities like striping null records, adding a header to a file, print only certain records like the FIND command.

Here is my program code. any more suggestions?

PROGRAM UP_CASE;
    Uses CRT, printer;
    VAR
    DATAFILE : TEXT;
    INREC    : STRING;
    OUTREC   : STRING;
    I        : WORD;
    C        : CHAR;
    S        : STRING;
    BEGIN
    Assign( DATAFILE, '' );
    Reset(DATAFILE);
    ASSIGN(LST, '');
    REWRITE(LST);
    WHILE NOT Eof( DATAFILE ) DO
        BEGIN
        OUTREC := '';
        READln(DATAFILE, INREC);
        FOR I := 1 TO LENGTH(INREC) DO
           BEGIN
             S := COPY(INREC,I,1);
             C := S;
             C := UPCASE(C);
             OUTREC := OUTREC + C;

           END;
        Writeln(LST, OUTREC );
        END;
     CLOSE(DATAFILE);
     CLOSE(LST);
    END.
Glenn9999 (Programmer)
26 Apr 06 16:48
upcase() is for a character only.  It's not uncommon for me to have to copy a function I made into the text to handle this job for an entire string:

something like (untested since I just typed it out this time):

CODE

function upstr(instr: string): string;
  var
    i: byte;
    outstr: string;
  begin
    outstr := instr;
    for i := 1 to length(outstr) do
      outstr[i] := upcase(outstr[i]);
    upstr := outstr;
  end;

Not really too much of a trouble to do, but must be done.
PROFESSORSPARKIE (Instructor)
26 Apr 06 22:11
TO GLENN9999

THANKS - it seems like a char variable could be assigned a byte directly from a string with the copy function using length 1 but it gets rejected. Looks like a suggestion for a compiler upgrade if these compilers were being maintained.

I first tried below, but no luck.

c := COPY(INREC,I,1);

then I could have used concat to put it back together.
 again THANKS, I will try it.
PROFESSORSPARKIE (Instructor)
26 Apr 06 22:46
TO GLENN9999

I can't believe how stupid I am. With over 44 years of programming experience on mainframes to PCs and I looked all around the solution. Your function reminded me that I could do direct indexing  on each byte in a string like a character variable. I was trying to use the "copy" function just as I would a "substr" function in "perl" or "mid$" function in "BASIC or "line.substring" in "java", etc.

PASCAL just doesn't work exactly the same. Close but not.

I just changed

c := COPY(INREC,I,1);
to
c := INREC[I];

and it worked like a charm.

THANKS for the tip.

Professorsparkie
PROFESSORSPARKIE (Instructor)
26 Apr 06 22:51
to glenn9999

I must have spent 5-6 hours off & on trying to force PASCAL to work the way I wanted.

I can't wait to tell my students. I have told them that programming is the most rewarding-frustrating activity in the computer field with mountain tops and valleys.

Again THANKS
professorsparkie

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close