deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You're returning a reference to a local variable. The local variable gets destroyed, so the reference is dangling. Just return a reference to myStore[row] directly:

template<class V, class I> 
V& Matrix<V,I>::operator()(int row, int column)
{   
    return myStore[row][column];
}

Alternatively you can make a local reference to the row, then return a reference to the column:

template<class V, class I> 
V& Matrix<V,I>::operator()(int row, int column)
{
    Array<V,I>& myArray = myStore[row];    
    return myArray[column];
}

On a side note, you should consider overloading the operator for const objects as well, and return a const reference:

template<class V, class I> 
const V& Matrix<V,I>::operator()(int row, int column) const;
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

But as i am returning a pointer s I can't free it before returning it.

The caller has to free it. While the ideal for robustness is to have memory allocated and freed at the same execution level, that's not always practical.

I take a char array[100],Perform operation on it,and then point my pointer to it at the end.

In this case you're returning a pointer to a local object. The local object gets destroyed when the function returns, so the caller gets what's called a dangling pointer--it points to garbage by definition.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Itworks fine for unsigned variables but the signed output is not correct for int or long.

You seem to have missed the part where I stated that overflowing a signed type is undefined behavior. The same method that works for unsigned types is broken on signed types. There's no safe way to do what you want with signed types, which is one reason why the standard library provides macros that tell you the range limits for the implementation.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

However, the values for INT_MIN and INT_MAX are shown in the appendices as being the same as SHRT_MIN and SHRT_MAX repsectively.

The minimum range of int is indeed 16 bits, even though you're unlikely to see less than 32 bits on a modern implementation.

I was hoping that by increasing a "short" variable, for example, to EOF, it would stop within its range. Why is this not occuring?

EOF is a negative quantity that may or may not be -1. What you're actually doing with that code is invoking undefined behavior by overflowing a signed integral type. A safer approach is to use unsigned types instead (since they have defined wraparound behavior), then stop when the value wraps to 0:

unsigned char x = 0;
unsigned short y = 0;
unsigned int z = 0;

while (++x != 0);
while (++y != 0);
while (++z != 0);

printf("Range of unsigned char [0,%u]\n", --x);
printf("Range of unsigned short [0,%u]\n", --y);
printf("Range of unsigned int [0,%u]\n", --z);
deceptikon 1,790 Code Sniper Team Colleague Featured Poster
#include <iostream>
#include <string>
#include <fstream>

int main()
{
    using namespace std;

    const int rows = 4;
    const int cols = 3;

    ifstream file("test.txt");

    if (file.is_open()) {
        float r[rows][cols];

        for (int i = 0; i < rows; ++i) {
            for (int j = 0; j < cols; ++j) {
                file >> r[i][j];
                file.get(); // Throw away the comma
            }
        }

        for (int i = 0; i < rows; ++i) {
            for (int j = 0; j < cols; ++j) {
                cout << r[i][j] << ' ';
            }

            cout << '\n';
        }
    }
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Thanks deceptikon for ur code and Checked it today and it's giving me some error, Can u tell me where I am going wrong

You're probably not using a compiler that supports C++11, or compiling with that switch disabled. However, I can't tell you what's wrong when you don't tell me what the errors are. :rolleyes:

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Two different concepts that unforunately seem similar due to the "over" part.

Overloading is when you have multiple functions that use the same name, but have different parameter lists. The function is said to be overloaded since calls that provide different arguments will call the correct function:

void foo() { cout << "No parameters\n"; }
void foo(int) { cout << "One parameter\n"; }

int main()
{
    foo();    // Prints "No parameters"
    foo(123); // Prints "One parameter"
}

Overriding is a concept related to polymorphism where a derived class' version of a member function is used instead of the base class' version. The derived class' function is said to override the base class' function:

class base {
public:
    virtual void foo() const { cout << "Base\n"; }
};

class derived: public base {
public:
    void foo() const override { cout << "Derived\n"; }
};

int main()
{
    const base& obj = derived();

    obj.foo(); // Prints "Derived"
}
ddanbe commented: Well explained +14
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Does your teacher want you to take the value as-is or round it? Regardless, you need to keep only the first two digits after the radix for the purposes of this program, but whether you round (and how you round) can affect the result.

A naive approach (which should be sufficient for this exercise) is to extract the two digits after the radix and convert it to int. Then look for the third digit after the radix and if it's greater than 5, round up. This should give you a decent facsimile of the rounding that cout performs:

#include <iostream>

using namespace std;

int main()
{
    double value = 14.49999;
    int ivalue = (int)((value - (int)value) * 1000);

    // Remove the dollar amount and convert cents to int
    int cents = ivalue / 10;

    // Find the rounding delta
    int delta = ivalue % 10;

    cout << "Cents: " << cents << '\n';
    cout << "Delta: " << delta << '\n';

    if (delta >= 5) {
        ++cents;
    }

    cout << "Cents rounded up: " << cents << '\n';
}

If you don't need to round, then you can take the cents as-is and call it good. But financial applications typically round up. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Your code is horribly broken. I'm guessing you meant to post the errors you're getting and ask what's causing them, as per this helpful guide.

Ketsuekiame commented: +1 +9
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

And in all reality I will be working with more than two files because I am working on an external polyphase sort

Okay, you're making it too complicated. You'll already have a collection of stream objects for a polyphase sort, so just mark the index of (or have a reference to) the current output stream and update it as necessary. That's so much more intuitive than swapping streams left and right, even if you were using C++11.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Thanks and How to write the file path in program?

...um, you may want to drop back a bit and study file I/O in C++. I had been operating under the assumption that your problem was parsing the format, not the basics of how to read a file.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

CSV is just a text format, so you'd open and read the file as you would any text file. However, you need to parse the format. For example using a very simple variant of CSV:

#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

int main()
{
    ifstream in("file.csv");
    vector<vector<double>> fields;

    if (in) {
        string line;

        while (getline(in, line)) {
            stringstream sep(line);
            string field;

            fields.push_back(vector<double>());

            while (getline(sep, field, ',')) {
                fields.back().push_back(stod(field));
            }
        }
    }

    for (auto row : fields) {
        for (auto field : row) {
            cout << field << ' ';
        }

        cout << '\n';
    }
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Daniweb is more of a Q&A forum for pointed questions and discussion. It's not well suited for teaching someone from scratch. Might I suggest Khan Academy?

ddanbe commented: Great suggestion! +14
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You're not using the sender parameter, so it can be anything (I'd just use Me). However, you are using the e parameter, so you need to fill out a new GridViewEventArgs object and pass it in:

Protected Sub btnEdit_Click(ByVal sender as Object, ByVal e As System.EventArgs) Handles btnEdit.Click
    Dim editArgs As New GridViewEditEventArgs With {.NewEditIndex = row}

    GridView1_RowEditing(Me, editArgs)
End Sub

In this case, row would be whatever row you want to edit. You may want to use the first selected index, or loop through all selected indices and call the RowEditing handler for each, but that's entirely application specific.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Also, please provide the purpose of this program.

It's pretty obvious that the purpose is to populate an array from a function.

but you aren't returning the edited variable nor are you passing it by reference.

Arrays are passed by simulated reference (ie. by pointer), so there's nothing wrong there. The two issues are thus:

  1. Semantic error: size is not a compile-time constant, and C++ doesn't allow array sizes that are not compile-time constants.

  2. Syntax error: The subscript operator is not used when passing an array to a function, just the array name.

The corrections are simple and obvious, provided the OP doesn't want a dynamically sized array:

#include <iostream>

using namespace std;

void getdata(int a[], int size);

int main()
{
    const int size = 10;

    int a[size];

    getdata(a, size);

    return 0;
}

void getdata(int a[], int size)
{
    for (int i = 0; i < size; i++)
        cin >> a[i];
}

You might say that failing to use the populated array is an error as well, since the only way to confirm the code works is by stepping through it in a debugger.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

One thing that should be noted is that the compiler can inline functions even when they're not declared as inline when it thinks doing so will be appropriate.

Also, inline is nothing more than a hint. The compiler is free to ignore it. That's one benefit (in a sea of downsides) to function-like macros: they're guaranteed inlining.

so, inline functions are always good to use in our code ?

I'd say the opposite. Inline functions are to be avoided until you can provide solid proof through a profiler that you've both got a bottleneck and that inline functions fix it. Otherwise they're not worth the hassle.

Can you please throw light on this statement ?

"the increased object code size results in excessive cache misses or thrashing."

Code gets loaded into memory in the form of instructions. You want your executing code to be loaded into a single cache line so that it's not swapped into RAM (slow) or even paged into virtual memory (hideously slow) an excessive number of times before completion.

When a function gets inlined, the calls are replaced with the whole of the function body rather than simply referencing the body through a call instruction, which can potentially increase your instruction size by orders of magnitude. So while you might save yourself the overhead of loading stack frames and executing call instructions, the overhead of duplicating code could cause you to cross those thresholds and be measurably slower than the …

nitin1 commented: awesome!! your way of explanation suits my understanding very much... +3
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

let's leave it at that instead of squabbling?

Provided it remains civil, "squabbling" amongst experts is a very good thing because a lot of ideas and information get thrown around for people to learn from.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The X,Y coordinates for each particle on your 2D plane is the random location. If all you want to do is to output the random location for each particle, then my example program is sufficient.

rubberman commented: pairtickle - my pairtickle physicist wife will chuckle at that one! :-) +12
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

We require that you show some proof of effort before offering any significant help. Do you have a specific issue that you encountered when trying to answer the question?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Not enough information. Is this a Windows form? A web form? WPF? Are you doing it all programmatically or using the Visual Studio designer? Typically such basic questions are better answered with a beginner's tutorial or book.

ddanbe commented: Good answer +14
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

@deceptikon, can you explain more? I didn't comprehend.

I can't really make it any simpler than this:

  1. The C++ standard doesn't currently allow it, and adding that feature in any useful way would be virtually impossible.
  2. Compiler support would be extremely difficult and error prone.

Just because something seems easy to you doesn't mean it's actually easy, especially when it comes to language and compiler design.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Does compiler allocates or reserved memory space from the data member the are not in use?

Yes.

I think, compilers are smart enough to determine which data member are in use of that object and which are not. So is there a reason (WHY and WHY NOT) they (DO or DO NOT) allocate space those resources?

Determining which data members are used is the easy part. Generating and managing each individual object that may have different used members makes my brain hurt just thinking about it.

Not to mention the insane rules that would need to be in place in the language definition to give us any semblance of consistency between compilers. I suspect those rules would be so draconian that any benefit you think you could get from this feature would quickly be reduced to nothing for the sake of portability and backward compatibility.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

So what is the answer ?

The answer is "it depends". You need to consider several issues stemming from the platform and compiler, including but not limited to:

  • Are the combination of operators you use to mimic multiplication faster than multiplication on your target platform?

  • Does the compiler optimize * into either your own bit twiddling code or something even faster? Compiler writers are smart folks, and usually their solutions are vastly superior to ad hoc stuff from application programmers.

  • Does the compiler optimize the multiplication away entirely? It doesn't matter how clever your trick is to mimic multiplication if the compiler can beat it by emitting nothing.

  • Does your tricky code confuse the compiler's optimizer such that the resulting machine code is slower than the equivalent multiplication?

There's no single answer to the question as it's one of those cases where your only recourse is to break out the profiler and do empirical testing.

sepp2k commented: Well said. +6
nitin1 commented: as usual, 1 man army for problems :D +3
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

im just gooing to leave this interesting article for the apple fans! :)

Hardly interesting. I've seen umpteen articles like that going in every direction, every which way, and always with different lists of features that are the "XYZ killer".

Though I especially enjoyed the mention of screen dimensions (a hardware feature) in a list comparing operating systems. Could the author not find enough legitimate OS features that "beat" iOS to make it a round 10? ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

if it has been done for once

How does it know? What if you've created other objects? What if those objects create objects behind the scenes or trigger events that spawn threads that create objects? It's not quite as simple as you seem to think, and you may be misunderstanding how the garbage collector works.

There's plenty of learning material on the .NET garbage collector. Maybe if you point to parts that you don't understand rather than paraphrasing how you think reality should work, it would be easier to help clarify things for you.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If it's .NET, the garbage collector is running. Whether it actually does something is up for debate, but there basically won't be a time when you have to worry about manually managing memory for stuff that the garbage collector handles.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Is this not correct?

Perfectly correct.

Generally in a conforming implementation foo = constant; foo == the_same_constant; should only ever produce false if foo and the constant have different types (and thus the assignment causes a conversion) - unless I'm missing something. Floating point inaccuracies should only bite you if you're doing arithmetic.

This is also the correct answer. As for why the OP's program failed to produce the correct behavior, we'd need to know details about the platform and compiler to diagnose non-conformancy. I'm willing to bet we're looking at a Turbo Crap quirk.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Most of us older folks lived our entire lives without a phone attached to our bodies, so what we never had we never miss.

And you walked 10 miles everywhere...up hill...both ways, and you were thankful for it. ;)

I didn't have a cell phone until my late 20s, but that doesn't make it any less useful to me now.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

And would you please tell me how to use the return statements for returning Matrices

Stop using arrays and switch to vectors (or a matrix class), that's how you do it:

vector<vector<int>> func();

There are some things that array types simply aren't suited for, and this is one of them.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The trick is that arrays in C are passed by simulated reference. The syntax you're using obscures it a bit, but these three declarations are functionally identical:

void getmat(int a[50][50],int n);
void getmat(int a[][50],int n);
void getmat(int (*a)[50],int n);

So an array is actually passed as a pointer to the first element, which is how you simulate pass by reference in C. And that's why when you scanf into a[i][j], it actually modifies the original array passed in from main.

The weirdness of arrays in C makes a lot more sense when you have a good handle on pointers.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What will be c++ equivalent of this snippet?

There would be no differences (barring the obvious syntax errors, but that would be broken in both languages). The FILE structure is a standard type inherited from C.

Also, is this struct correct for c++?

Yes.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I hate that new menu strip across the top which many programs are duplicating today. Very confusing.

Ribbons are universally hated by every IT department I've worked with (not an insignificant number). It's pandering to the dummy market and throwing power users under the bus.

I actually like the new Paint though. It's a nice happy medium between the bitmap editor it used to be and a fully featured package like GIMP.

What really bothers me is the current Windows Calculator. I hate switching between Programmer and Scientific mode because the former doesn't allow floating point and the latter doesn't allow alternate bases yet I use both on the regular.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

A slightly simpler explanation is that the arrow operator is syntactic sugar for accessing a member of a pointer to structure or class: p->member is equivalent to (*p).member. Since the latter is awkward to type and it's very common to have a pointer to a structure or class, the arrow operator was introduced as a syntactic convenience.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Keep in mind we are dealing with C here and not C++.

Just because it's in the C forum doesn't mean the OP isn't using some subset of C++ or compiling as C++. The error strongly suggests that string isn't being parsed as an object. Given that C++ supports a string type with the name string, it's not unreasonable to question which language we're working with here.

I wonder if the OP's compiler is assuming a one-parameter prototype, like extern int strcpy(char *x) as opposed to extern int strcpy(), which knows nothing about its indefinite number of parameters.

That's reaching a bit. ;) Any compiler that assumes the former rather than the latter is broken and non-conforming. I know for a fact that Visual C++ is conforming in this case.

Besides, with a mismatch between the call and definition given an implicit declaration, the actual error would happen at link time rather than the compile time syntax error the OP is seeing.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

but im not sure how i would fix that one as of now.

Move all declarations to the top of the current scope. For example with your main.c:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "player.h"
#include "other.h"

int main(int argc, char const *argv[])
{
    dug * one = malloc(sizeof(dug) * 1);
    player * us = malloc(sizeof(player) * 1);
    FILE *sy;

    us->cheat = malloc(sizeof(int)* 1);
    *us->cheat = 0;

    sy = fopen("story.txt", "a");

    us->name = malloc(sizeof(char)* 40);
    us->HP = malloc(sizeof(int)* 1);
    us->dir = malloc(sizeof(int)* 1);
    us->help = malloc(sizeof(int)* 1);

    one->torch = malloc(sizeof(int)* 1);
    *one->torch = 1;

    *us->HP = 10;
    *us->dir = 3;//1 north, 2 east,3 south,4 west
    *us->help = 0;

    one->WIN = malloc(sizeof(int)* 1);
    *one->WIN = 0;

    printf(" What is your name:");
    scanf("%s", us->name);
    fprintf(sy, "The journals of %s\n", us->name);

    RoomOne(us, one, sy);

    if (*one->WIN == 0) {
        printf("Game Over,%s\n", us->name);
        fprintf(sy, "\tLast entry, %s\n", us->name);
        if (*us->cheat == 1) {
            printf("winners never cheat, and cheater's never win.\n");
        }
    }
    if (*one->WIN == 1) {
        printf("You have escaped the dark, Now face the light.\n");
        fprintf(sy, "you have won the game, %s.\n", us->name);
    }

    fclose(sy);
    return 0;
}

Easy peasy. Prior to C99, C doesn't allow declarations to be mixed with executable code; declarations always come first.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

g++ doesn't complain about the OP's code, even if I add #include <string> and using std::string.

But you didn't compile the code as it is, because it's only a snippet; you had to add scaffolding for it to compile. I bet you're assuming that the OP's example is something along the lines of this (assuming C++):

#include <string>

using namespace std;

int main()
{
    char string[6];

    strcpy(string, "HELLO\0");
}

Which compiles just fine in Visual Studio (boo for intrinsics), and probably would in g++ as well. However, it could very easily be this:

#include <string>

using namespace std;

char string[6];

int main()
{
    strcpy(string, "HELLO\0");
}

Which pukes with an ambiguity error. That's why more code is needed to diagnose this issue. When using variable names that could potentially be macro or type names, the exact usage is very important.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Just because '\0' is added automatically doesn't mean you can't refer to it explicitly. The code is perfectly legal C, but I suspect the OP is compiling it as C++ where string is very likely to cause issues due to potentially being exposed as a type name.

The code as it stands is fine. A more complete example would help in diagnosing this error.

Try \x00 or leave the \0 off.

'\0' and '\x00' are synonymous.

So it is trying to copy 7 characters into 6 spaces, 5 for HELLO and 2 null characters. Avoid using the null character in the string literal.

strcpy stops copying at the first null character, so the problem you've described does not exist.

sepp2k commented: Nicely figured out. +6
Nutster commented: Quite right. I realized that when I reread my response, thinking, "Wait it will stop when it gets to the first null." Also that does not explain the compiler error.. +6
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I find it extremely unlikely that a teacher would give you an assignment without covering any of the material needed to complete it. The problem is more likely on your end in not going to class or not paying attention. In that case, you get what you deserve and the failing grade should be a good lesson in itself.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Flood control isn't presently enabled for voting, to the best of my knowledge. Dani may have implemented it in a non-obvious way without me noticing though. ;)

In light of the recent complaints, I've stepped up the priority of a moderator tool I wanted to write that lets us investigate (and possibly in the future, reverse) vote records without having to directly query the database. Pending Dani's approval, that should at least make it easier to determine if it's potentially a matter of harrassment.

LastMitch commented: Good Job, Autobot! =) +0
~s.o.s~ commented: What kind of a crazy sig is that? ;) +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You can preview the message at any time by clicking on the Spellcheck/Preview button on the editor. We also give you sufficient time to edit your post after submitting it.

Should you want a post deleted, you're welcome to report it with the Flag Bad Post button. This will place it in the queue for moderation and a moderator can delete it. However, keep in mind that if there are any replies to one of your threads that you want deleted or deleting one of your posts might break thread continuity, we won't do it.

Reporting a post after the edit window is also acceptable if you want reasonable changes made.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

There's no return statement, yet the method is supposed to return bool...

ChrisHunter commented: Bob-on +7
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

There were always 8 bits in a byte.

That's not universally true. To the best of my knowledge there aren't any platforms where a byte is less than 8 bits, but there certainly are platforms where it's more.

Why create an encoding standard that is stored with multiple 0's when say this could be done with 16 bits or 8 bits..

Storage cost is only a part of the problem. When you have complex encoding methods, it takes time to process them. UTF-32 is the ideal when you can afford the space because it's a lot faster than encoding and decoding UTF-16 or UTF-8 compression. UTF-16 and UTF-8 were designed to reduce storage cost, and the price of that is reduced performance.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

<< doesn't represent a sequence point, so the example is undefined.

nitin1 commented: :p +1 thanks once again +3
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Think of programming like the martial arts. You can probably learn the basics quickly, but it's not very useful at that level. To reach and maintain a level where it is useful, you have to put in a lot of effort. And anyone who tells you it's easy is trying to sell you something. ;)

<M/> commented: Yup, that's accuarate +8
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

In general, boolean logic precedence rules place NOT first, then AND, then OR. So in your example, it would go like this:

(NOT (X OR Y)) AND Z

Or broken down using temporaries:

A = X OR Y
B = NOT A
C = B AND Z
Q = C
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Would make str str?

I don't understand your question, but if you're asking whether you want to use the strstr function then the answer is yes. strstr will return a pointer to the matched string, or NULL if it wasn't found. So you can repeatedly call strstr and then skip over the match:

char *p = line;
char *match;
int n = 0;

while ((match = strstr(p, key)) != NULL) {
    /* Update the match counter */
    ++n;

    /* Skip over the match so it isn't found again */
    p = match + key_len;
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

There's not really a 'for Dummies' level book because the topic is very complex. The O'Reilly book is probably your best bet for an introduction, and if it's too difficult you're probably lacking in prerequisite education.

Perhaps if you point out some parts of the book that are troublesome, we can clarify things or point you toward a resource for further learning.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The answer is 214. All you need to do is recognize that you're working in base 8 rather than base 10.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Then use getchar instead of scanf to read each digit as a character. Much easier:

#include <ctype.h>
#include <stdio.h>

int main(void)
{
    int ch;

    while (isdigit(ch = getchar()))
    {
        switch (ch)
        {
        case '0': fputs("zero ", stdout); break;
        case '1': fputs("one ", stdout); break;
        case '2': fputs("two ", stdout); break;
        case '3': fputs("three ", stdout); break;
        case '4': fputs("four ", stdout); break;
        case '5': fputs("five ", stdout); break;
        case '6': fputs("six ", stdout); break;
        case '7': fputs("seven ", stdout); break;
        case '8': fputs("eight ", stdout); break;
        case '9': fputs("nine ", stdout); break;
        }
    }

    putchar('\n');

    return 0;
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

So Now I have 2 infraction points. I don't see which rule i broke.

You've been here long enough to know we have a C forum and that C questions go in the C forum. I had to move this thread from Community Center, and thus felt justified in giving you an infraction for Keep It Organized.

If you read the PM that was sent automatically with my reason comment, you'd know this though.