Thread: Reading from an Array

  1. #1
    Registered User
    Join Date
    May 2020
    Posts
    1

    Reading from an Array

    Hi, very new to C.

    I have a project that requires me to input a string into a rail fence cipher, I have created a function and passed the string to it, created a 2d array and then printed off the coded text but this is within the function and read straight from the array.

    How do I allocate the output of the array to a string then pass that from the function back to main?

    thanks in advance for any help.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    > How do I allocate the output of the array to a string then pass that from the function back to main?
    Rather than doing
    output = cipher(input);

    Do
    cipher(input,output);

    Make the caller responsible for the initial allocation, because they ultimately have to deal with the cleanup anyway.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. reading from a 2d array
    By roaan in forum C Programming
    Replies: 5
    Last Post: 09-03-2009, 11:42 PM
  2. reading through an array
    By ammochck21 in forum C++ Programming
    Replies: 11
    Last Post: 11-29-2006, 07:02 AM
  3. help reading array
    By hkl01 in forum C++ Programming
    Replies: 9
    Last Post: 05-04-2006, 05:21 PM
  4. Replies: 1
    Last Post: 04-25-2006, 12:14 AM
  5. reading into array
    By 98holb in forum C Programming
    Replies: 1
    Last Post: 01-26-2006, 11:35 AM

Tags for this Thread