473,323 Members | 1,589 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

task is to find out whether the given string is a super ascii string or not.

#include<stdio.h>
main()
{
char s[10],a=0,b=0,c=0;
int i=0;
printf("enter");
gets(s);
while(s[i]!='\0')
{
switch(s[i])
{
case'a':a++;
break;
case'b':b++;
break;
case'c':c++;
break;
}
if(a=1)&&(b=2)&&(c=3)
printf("yes");
else
printf("no");
}

i'm getting expression syntax error
Aug 13 '14 #1
2 2303
weaknessforcats
9,208 Expert Mod 8TB
This code:

Expand|Select|Wrap|Line Numbers
  1. if(a=1)&&(b=2)&&(c=3)
  2. printf("yes");
  3. else
  4. printf("no");
  5. }
  6.  
is missing outer parentheses. The format of an if statement is:

Expand|Select|Wrap|Line Numbers
  1. if (something)
  2. etc...
so you should have:
Expand|Select|Wrap|Line Numbers
  1. if ((a=1)&&(b=2)&&(c=3))
  2. printf("yes");
  3. else
  4. printf("no");
  5. }
  6.  
also be aware a=1 des not mean a equals 1. It means to assign 1 to a. You probably want:

Expand|Select|Wrap|Line Numbers
  1. if ((a==1)&&(b==2)&&(c==3))
  2. printf("yes");
  3. else
  4. printf("no");
  5. }
  6.  
Aug 13 '14 #2
donbock
2,426 Expert 2GB
By the way, use of the gets() function has been deprecated for many years. In fact, this function has been removed from the latest version of the C Standard (C11).
I suggest you replace gets(s) with fgets(s,10,stdin).
This won't fix any syntax errors, but it may prevent later run-time errors.
Aug 13 '14 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Willem | last post by:
What is the best way to calculate an ascii string into an integer (not talking about an atoi conversion): For examle if I have the ascii string: "/b" then in hex it would be 2F7A and if I...
11
by: Kai Bohli | last post by:
Hi all ! I need to translate a string to Ascii and return a string again. The code below dosen't work for Ascii (Superset) codes above 127. Any help are greatly appreciated. protected...
3
by: Michel Racicot | last post by:
I need to read a null terminated ASCII string from a FileStream. How can I do that? I know that with FileStream.ReadByte, I can read until I get a byte == 0 but how can I convert a single byte to...
2
by: Claire | last post by:
Would someone give me a code example that reads an ASCII string from a binary reader and converts it to a c# string please. I find that the help files aren't very clear on how do do this eg "DATA"...
4
by: Vishal | last post by:
I need a simple method to find whether there are any instances of consecutive commas (more than 1) in a given string without parsing each character of the string. I tried with strtok() with comma...
18
by: Ger | last post by:
I have not been able to find a simple, straight forward Unicode to ASCII string conversion function in VB.Net. Is that because such a function does not exists or do I overlook it? I found...
4
by: Emilio | last post by:
Question about Shared Sub Connect(server As , message As ) Why is in square brackets? Is it like Shared Sub Connect(server() As String, message() As String)
18
by: John | last post by:
Hi, I'm a beginner is using C# and .net. I have big legacy files that stores various values (ints, bytes, strings) and want to read them into a C# programme so that I can store them in a...
2
by: John Nagle | last post by:
I'm trying to clean up a bad ASCII string, one read from a web page that is supposedly in the ASCII character set but has some characters above 127. And I get this: File...
1
by: davidpryce123 | last post by:
Dear Group. For an application I am developing I need to display a 64 bit bitmap as a compressed ascii string of bits. This is to allow for the easier understanding of the bits for the users....
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.